Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用哈希密码添加密码验证系统?_Php_Html_Codeigniter - Fatal编程技术网

Php 如何使用哈希密码添加密码验证系统?

Php 如何使用哈希密码添加密码验证系统?,php,html,codeigniter,Php,Html,Codeigniter,顺便说一下,我正在使用PHP和CodeIgniter版本3, 因此,我目前正在开发一个新的网站,用于记录任何市场的销售数据。我目前在注册系统中苦苦挣扎。 我的意思是如何用用户输入的密码验证散列密码 这是剧本 public function cek_login() { $email = set_value('email'); $password = set_value('password');

顺便说一下,我正在使用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_规则('email'、'email'、'required | valid_email');
$this->form_validation->set_规则('password','password','required');
如果($this->form\u validation->run()==FALSE)
{
重定向(“/”);
}否则{
$auth=$this->M_login->cek_login();
如果($auth==FALSE)
{
回声'
window.location.href=“”.base_url('C_login')”;
警报(“Terjadi kesalahan silahkan cek ulang电子邮件和密码anda”);
';
}否则{
如果($auth['verified']=1){
回声'
window.location.href=“”.base_url('C_login')”;
警报(“电子邮件”);
';
}
否则{
$this->session->set_userdata('id',$auth->id);
$this->session->set_userdata('email',$auth->email);
$this->session->set_userdata('nama',$auth->nama);
回声'
window.location.href=“”.base_url('C_login')”;
警报(“登录Berhasil”);
';
}
}
}
}

虽然我坚信您需要做大量的学习,但我将留下这个答案,以便在您进行项目时为您指明正确的方向

对于注册,您需要使用PHP内置的哈希函数
password\u hash()
对密码进行哈希运算。因此,您的注册函数应该如下所示:

public function cek_register()
{
    // get other fields for the registration and validate
    $user_password = $this->input->post('password'); // password field

    // Hash the password
    $hashed_password = password_hash($user_password, PASSWORD_DEFAULT);

    // You can store the $hashed_password in your database as you wish
}
对于登录,您需要验证密码,如下所示:

public function cek_login()
{
    // First you check if the supplied email is stored in the database
    // If yes, you get the password field of that stored email
    // Then you verify the password if it matches which the user has entered like so:
    if ( password_verify($the_entered_password, $the_password_stored_in_the_database) )
    {
        // The user is valid, log user in
    }
    else 
    {
        // Wrong password, show error message
    }
}
以下是您应该查看的一些链接:

将输入密码转换为哈希,然后与现有密码进行比较。您能用脚本回复吗?这将对我很有帮助,并且直接内置到PHP中,并且尽可能简单。如果您尝试过实现它们,但遇到了问题,请发布一个新的解决方案和清晰的问题描述。好的,感谢您提供的链接,并对错误表示抱歉。下次我会好起来的