Php密码\u验证代码Igniter3
我在验证密码方面没有什么问题。 我使用codeigniter 3进行研究 我有一个用户模型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
<?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.netpassword\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