【发布时间】:2020-12-03 15:57:29
【问题描述】:
顺便说一下,我正在使用 PHP 和 CodeIgniter 版本 3, 所以我目前正在为任何市场开发一个新的销售数据记录网站。我目前在注册系统中苦苦挣扎。 我的意思是如何使用用户输入的密码验证散列密码。
这是脚本
public function cek_login()
{
$email = set_value('email');
$password = set_value('password');
$result = $this->db->where('email', $email)
->where('password', $password)
->limit(1)
->get('account');
if($result->num_rows() > 0){
return $result->row();
} else{
return array();
}
}
` 并且模型是
public function loginproses()
{
$this->form_validation->set_rules('email','email','required|valid_email');
$this->form_validation->set_rules('password','password','required');
if($this->form_validation->run() == FALSE)
{
redirect('/');
} else{
$auth = $this->M_login->cek_login();
if($auth == FALSE)
{
echo '<script>
window.location.href="'.base_url('C_login').'";
alert("Terjadi kesalahan silahkan cek ulang Email dan Password anda");
</script>';
} else{
if($auth['verified'] = 1){
echo '<script>
window.location.href="'.base_url('C_login').'";
alert("Email");
</script>';
}
else{
$this->session->set_userdata('id', $auth->id);
$this->session->set_userdata('email', $auth->email);
$this->session->set_userdata('nama', $auth->nama);
echo '<script>
window.location.href="'.base_url('C_login').'";
alert("Login Berhasil");
</script>';
}
}
}
}
【问题讨论】:
-
将输入的密码转换为hash,然后与已有的密码进行比较
-
你能用脚本回复吗?对我有帮助
-
php.net/manual/en/function.password-hash.php 和 php.net/manual/en/function.password-verify.php 直接内置在 PHP 中,并且尽可能简单。如果您尝试实施它们但遇到问题,请发布minimal reproducible example 和清晰的问题描述。
-
好的,谢谢你的链接,对错误深表歉意。下次我会更好
标签: php html codeigniter