该代码始终返回错误的用户名和密码,尽管其正确且相同的功能适用于我的管理员登录系统。它在一段时间前有效,但现在不起作用了。
function login($user,$pass,$accountType){
require('connection.php');
$result=mysqli_query($con,"select * From $accountType");
$regex="/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/";
if(preg_match($regex, $user)){
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
$username=$row['username'];
$password=$row['password'];
if($user==$username){
if (password_verify($pass,$password)){
if($accountType=='student'){
$_SESSION['student']='$user';
header('Location:studentprofile.php');
exit();
}
elseif($accountType=='teacher'){
$_SESSION['student']='$user';
header('Location:teacherprofile.php');
exit();
}
elseif($accountType=='admin'){
header('Location:admin.html');
exit();
}
}
else
{
$_SESSION['error']="wrong password"."<br>";
}
}
else{
$_SESSION['error']="Wrong username "."<br>";
}
}
}
else{
$_SESSION['error']="No data found";
}
}
else{
$_SESSION['error']="not a valid email,";
}
}
从注释 “我已指定varchar(20)在数据库中存储密码”
密码字段应该很大。所述password_hash()
可产生一些非常冗长的文字(当前的默认是60个字符),所以使场较大,如varchar(254)
或text
将允许所需要的长度。PHP团队正在向该方法添加更多算法,这意味着哈希可以并且将会增长。我们也不想限制用户使用自己选择的密码或密码短语的能力。最好为更改留出空间
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句