【发布时间】:2016-07-14 21:17:03
【问题描述】:
尝试为个人项目编辑一些代码但没有成功。我希望 $shapassword 输出中的用户名和密码在数据库中全部大写。下面是代码,具体看这个
$shapassword = sha1($username . ":" . $password);
这是完整的代码
public function register($post)
{
if (!isset($post['username']) || empty($post['username']) || !isset($post['password']) || empty($post['password']) || !isset($post['passwordrep']) || empty($post['passwordrep']) || $post['password'] != $post['passwordrep'] || !isset($post['email']) || empty($post['email'])) {
die("Unknown error!");
}
$username = $this->escape($post['username']);
$password = $this->escape($post['password']);
$shapassword = sha1($username . ":" . $password);
$email = $this->escape($post['email']);
if (!$this->checkEmail($email)) {die("Error - E-Mail alreadly exists in our database.");}
if (!$this->checkUsername($username)) {die("Error - Username already exists in our database.");}
$query = "INSERT INTO " . $this->core->loaded['table'] . " (";
foreach ($this->core->loaded['fields'] as $field => $value) {
if ($query == "INSERT INTO " . $this->core->loaded['table'] . " (") {
$query = $query . "`" . $field . "`";
} else {
$query = $query . ", `" . $field . "`";
}
}
$query = $query . ") VALUES (";
$qe = $query;
foreach ($this->core->loaded['fields'] as $field => $value) {
if ($query == $qe) {
$query = $query . "'" . $this->format($username, $password, $shapassword, $email, $value) . "'";
} else {
$query = $query . ", '" . $this->format($username, $password, $shapassword, $email, $value) . "'";
}
}
$query = $query . ");";
$this->DBC->query($query);
if ($this->DBC->errno) {die($this->DBC->error);} else {die("true");}
if ($this->config->email_notification) {
$subject = $this->format($username, $password, $shapassword, $email, $this->config->email_subject);
$text = $this->format($username, $password, $shapassword, $email, $this->config->email_text);
$headers = "From :" . $this->config->email_email;
mail($email, $submit, $text, $headers);
}
}
}
我相当肯定这是一个简单的修复,但我无法让它工作。如果您能提供帮助,那就太好了,谢谢。
【问题讨论】:
-
我看不到您在这里尝试在哪里执行大写方法。你为什么使用sha1?我希望你不会忍受这个。
-
感谢您的及时回复,我需要$shapassword以大写形式输出,我相信这与代码的第一个sn-p有关。这只是一个个人项目,不会上线。 sha1 是一项要求。