我在做一个登录页面,我需要使用CodeIgniter访问我的数据库中的hashpassword。用于登录的Codeigniter和哈希密码?
我hashPassword功能是:
function hashPassword($pass, $passKey){
$key = base64_decode($passwordKey);
return base64_encode(hash_hmac(
'sha256',
$key . mb_convert_encoding($password, 'UTF-16LE', 'ASCII'),
$key, true));
}
我必须做到以下几点:
- 用户的
id
使用他们username
- 提取
password
和passwordKey
my_aspnet_Users
表从my_aspnet_Membership
使用提取其编号 - 检查是否
password
等于hashPassword(<password entered by user>, passwordKey)
以知道输入的密码是否有效。
所以,我有两个型号:
Class Password extends CI_Model{
function getPassword($password, $passwordKey){
$this -> db -> select ('userId, Password, PasswordKey');
$this -> db -> from ('my_aspnet_Membership');
$this -> db -> where ('Password = '. "'" . $password . "'");
$this -> db -> where ('PasswordKey = '. "'" . $passwordKey . "'");
$q = $this -> db -> get();
if ($q -> num_rows() == 1){
return $q ->result();}else{
return false;
}
}
}
和..
Class User extends CI_Model{
function getUser($id){
$this -> db -> select('id, name ');
$this -> db -> from('my_aspnet_Users');
$this -> db -> where('id = '. "'". $id . "'");
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1){
return $query->result();
}
else{
return false;
}
}
}
我只是不知道如何让他们共同借此在密码检查。