Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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密码\u验证代码Igniter3_Php_Codeigniter - Fatal编程技术网

Php密码\u验证代码Igniter3

Php密码\u验证代码Igniter3,php,codeigniter,Php,Codeigniter,我在验证密码方面没有什么问题。 我使用codeigniter 3进行研究 我有一个用户模型 <?php class User_model extends CI_Model{ public function __construct() { parent::__construct(); $this->load->database(); } public function createUser($args): in

我在验证密码方面没有什么问题。 我使用codeigniter 3进行研究

我有一个用户模型

<?php

class User_model extends CI_Model{

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function createUser($args): int
    {
        $query = $this->db->insert('user', $args);
        return $this->db->affected_rows();
        
    }

    public function getUser(string $email): array
    {
        $query = $this->db->get_where('user',array('email'=> $email));
        return $query->row_array();
    }

}
作为php.net
密码验证()
验证通过
密码散列()创建的密码

如果使用sha256哈希,则可以更好地对用户输入进行哈希,并与DB查询的密码进行比较,如下所示:

$password = $this->input->post('password');
if(hash('sha256', $password) == $hash) {
 echo 'success';
} else {
 echo 'failed';
}
$user_query = $this->db->get_where('users', array('email' => $email, 'password' => hash('sha256', $password));
if($user_query->num_rows() == 0) {
 print 'failed';
} else {
 print 'success';
 $user = $user_query->row_array();
 ...
}
我认为更好的方法是在查询中动态检查密码,如下所示:

$password = $this->input->post('password');
if(hash('sha256', $password) == $hash) {
 echo 'success';
} else {
 echo 'failed';
}
$user_query = $this->db->get_where('users', array('email' => $email, 'password' => hash('sha256', $password));
if($user_query->num_rows() == 0) {
 print 'failed';
} else {
 print 'success';
 $user = $user_query->row_array();
 ...
}
顺便说一句:最好使用CodeIgniters$this->input->post('password'),因为它可以为您进行安全过滤。

因为php.net
password\u verify()
验证通过
password\u hash()创建的密码。

如果使用sha256哈希,则可以更好地对用户输入进行哈希,并与DB查询的密码进行比较,如下所示:

$password = $this->input->post('password');
if(hash('sha256', $password) == $hash) {
 echo 'success';
} else {
 echo 'failed';
}
$user_query = $this->db->get_where('users', array('email' => $email, 'password' => hash('sha256', $password));
if($user_query->num_rows() == 0) {
 print 'failed';
} else {
 print 'success';
 $user = $user_query->row_array();
 ...
}
我认为更好的方法是在查询中动态检查密码,如下所示:

$password = $this->input->post('password');
if(hash('sha256', $password) == $hash) {
 echo 'success';
} else {
 echo 'failed';
}
$user_query = $this->db->get_where('users', array('email' => $email, 'password' => hash('sha256', $password));
if($user_query->num_rows() == 0) {
 print 'failed';
} else {
 print 'success';
 $user = $user_query->row_array();
 ...
}

顺便说一句:最好使用CodeIgniters$this->input->post('password'),因为它可以为您进行安全过滤。

非常感谢!:太感谢你了D