在我正在制作的应用程序中,我需要匆忙编辑和创建一些密码,我想我已经找到了一种方法,但我怀疑它的正确性。
我仔细研究了 ion auth 并在 ion_auth_model
中找到了这个功能。
/**
* Hashes the password to be stored in the database.
*
* @return void
* @author Mathew
**/
public function hash_password($password, $salt=false, $use_sha1_override=FALSE)
{
if (empty($password))
{
return FALSE;
}
//bcrypt
if ($use_sha1_override === FALSE && $this->hash_method == 'bcrypt')
{
return $this->bcrypt->hash($password);
}
if ($this->store_salt && $salt)
{
return sha1($password . $salt);
}
else
{
$salt = $this->salt();
return $salt . substr(sha1($salt . $password), 0, -$this->salt_length);
}
}
并通过在我的一个 Controller 中创建此公共(public)函数进行测试
public function Qpass_gen(){
$pass = $this->ion_auth_model->hash_password('password',FALSE,FALSE);
echo $pass;
}
当我更换
Qpass_gen()
时字符串与 ion_auth 默认存储在数据库中的字符串,我设法登录。我的快速生成密码的方法是否保证始终有效?
最佳答案
是的,这是处理它的好方法。作为图书馆的作者,这就是我推荐的。
关于php - Codeigniter Ion Auth 生成密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27998594/