我想验证输入的密码是否正确。我使用以下代码,
控制器
$pWord = $_POST['pword'];
if($this->model_users->check($uName) == $pWord) {
echo 'Loggedin!';
} else {
echo 'Incorrect password!';
}
模型
function check($username) {
$query = $this->db->query("SELECT password FROM user WHERE user_name= '$username'");
if ($query->num_rows() > 0) {
return $query->result();
} else {
return NULL;
}
}
查看
<form action="/test/index.php/login/valid" method="POST">
Username :<input name="uname" type="text"> <br><br>
Password :<input name="pword" type="password"> <br><br>
<input type="submit" value="Enter">
</form>
但我无法得到“Loggedin!”当我输入数据库中存在的正确密码时。
答案 0 :(得分:0)
您必须返回密码,而不是结果数组。使用以下代码
function check($username) {
$query = $this->db->query("SELECT password FROM user WHERE user_name= '$username'");
if ($query->num_rows() > 0) {
return $query->row()->password;
} else {
return NULL;
}
}