我將sha512
添加到此登錄表單中,但我一直收到錯誤無效的用戶名或密碼。 我用http://www.convertstring.com/Hash/SHA512來設置數據庫中的密碼登錄表單並不閱讀sha512
它爲什麼不起作用?數據庫中的密碼用sha512 +鹽進行哈希處理,但我不斷收到用戶名/密碼不正確的錯誤。
if(isset($_POST['submit'])) {
$password1 = ($_POST['password_']);
$salted = "b5vy2m92m9c5my925myic52ddqwm534itkic4m3timcy35".$password1;
$hashed = hash('sha512', $salted);
if(!$_POST['username_'] || !$hashed) {
echo '<div class="alert alert-block alert-danger"><button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>Complete all fields.</div>';
} else {
$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `name` = ? AND `password` = ?');
$q->execute(array($_POST['username_'], $hashed));
登錄形式
<input type="text" name="username_"/><br/>
<input type="password" name="password_"/><br/>
<input type="submit" name="submit" value="login" class="btn btn-inverse">
總腳本:
if(isset($_SESSION['user'])) echo '<script>
location.replace("'.Config::$_PAGE_URL.'"); </script>'
if(isset($_POST['submit'])) {
$password1 = ($_POST['password_']);
$salted = "b5vy2m92m9c5my925myic52ddqwm534itkic4m3timcy35".$password1;
$hashed = hash('sha512', $salted);
if(!$_POST['username_'] || !$hashed) {
echo '<div class="alert alert-block alert-danger"><button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>Complete all fields.</div>';
} else {
$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `name` = ? AND `password` = ?');
$q->execute(array($_POST['username_'], $hashed));
if($q->rowCount()) {
$d = Config::$g_con->prepare('SELECT * FROM `panel_restrict` WHERE `PlayerName` = ?');
$d->execute(array($_POST['username_']));
$row1 = $d->fetch(PDO::FETCH_OBJ);
if($d->rowCount() && date("Y-m-d H:i:s") <= gmdate("Y-m-d H:i:s", $row1->Time)) {
if($row1->Permanent == 1) {
$expira = "<b>permanent</b>";
} else {
$expira = "pana la data de <b>". gmdate("Y-m-d H:i:s", $row1->Time) ."</b>";
}
echo '<div class="alert alert-block alert-danger">
Contul tau este suspendat '.$expira.'.<br />
Motiv: <b>'.$row1->Reason.'</b><br />
Banat pe data de <b>'.$row1->BanTimeDate.'</b></div>';
} else {
$dele = Config::$g_con->prepare("DELETE FROM panel_restrict WHERE PlayerName = ?");
$dele->execute(array($_POST['username_']));
$row = $q->fetch(PDO::FETCH_OBJ);
$_SESSION['user'] = $row->id;
echo '<script> location.replace("'.Config::$_PAGE_URL.'"); </script>';
//setcookie ("user",$_POST['username_'],time()+3600*24*60);
//setcookie ("password",$_POST['password_'],time()+3600*24*60);
//header ('Location: ' . $_PAGE_URL);
}
}
else echo '<div class="alert alert-block alert-danger"><button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>Invalid username or password.</div>';
}
}
重新開始然後用戶'password_hash()'和'password_verify()'閱讀手冊 –
什麼類型的數據庫中的密碼字段? – monkeyinsight
我使用\t varchar(256)作爲密碼,\t varchar(64)作爲用戶名 –