簡體   English   中英

無法登錄,無法檢查密碼?

[英]Can't login, trouble checking password?

昨天,我開始制作自己的登錄+注冊表格。

 // ...Variable checking... // Final upload if ($errornum == 0){ if (!file_exists("../core/accounts/".$username.".php")) { $password_e = password_hash($password, PASSWORD_DEFAULT, ['cost' => 10]); $myFile = "../core/accounts/".$username.".php"; $fh = fopen($myFile, 'w'); $stringData = "<?php\\n\\$username_u = \\"{$username}\\";\\n\\$password_u = htmlentities(\\"{$password_e}\\", ENT_QUOTES);\\n\\$gender_u = \\"{$gender}\\";\\n\\$birth_day_u = \\"{$birth_day}\\";\\n\\$birth_month_u = \\"{$birth_month}\\";\\n\\$birth_year_u = \\"{$birth_year}\\";\\n\\$status_u = \\"{$status}\\";\\n\\$email_u = \\"{$email}\\";\\n\\$firstname_u = \\"{$firstname}\\";\\n\\$lastname_u = \\"{$lastname}\\";\\n\\$refer_u = \\"{$refer}\\";\\n?>"; fwrite($fh, $stringData); fclose($fh); } else {$username_error.="<div id='error'>Username taken</div>"; $errornum = $errornum + 1;} } 

那就是注冊上傳的東西。 它的作用:將所有用戶輸入的變量存儲在位於core / accounts / user-name.php的文件中。

這是上面的代碼生成的文件的輸出:

 // The password is "dummypassword" // The file name, in this case, is "dummyfile.php" <?php $username_u = "dummyfile"; $password_u = htmlentities("$2y$10$1s7uJ4yM5u6KxKdiCh3P0.S/zQRDT4C9DtakCtmJvwR/SxwjVsXzC", ENT_QUOTES); $gender_u = "male"; $birth_day_u = "3"; $birth_month_u = "2"; $birth_year_u = "1977"; $status_u = "single"; $email_u = "dummyemail@gmail.com"; $firstname_u = "dummy"; $lastname_u = "dummy"; $refer_u = "me"; ?> 

如您所見,密碼已通過以下“命令”進行了加密:

password_hash($password, PASSWORD_DEFAULT, ['cost' => 10]);

我正在使用htmlentities(); 存儲密碼中包含的特殊字符。 這是登錄腳本...

 // ...Self explanatory code above... No need to include $submit = trim(stripslashes(strip_tags(($_POST['submit'])))); if(!empty($submit)){ $username = trim(stripslashes(strip_tags(($_POST['username'])))); $password = trim(stripslashes(strip_tags(($_POST['password'])))); if(empty($username) || empty($password)){ $error=true; } else { if (file_exists("core/accounts/".$username.".php")) { include "core/accounts/".$username.".php"; } else {$error=true;} if(password_verify($password, $password_u)){ // Logged in!! $_SESSION['username'] = $username; header("location:home/"); exit; } else {$error=true;} } 

同樣,真正有趣的部分是以下“命令”:

if(password_verify($password, $password_u)){

問題是,它不起作用。 我無法登錄。 它總是告訴我密碼錯誤! 我知道錯誤一定是由於我提到的命令引起的。

有小費嗎?

如果您傾向於做自己在做的事情,但我不明白...

改變,這個...。

if(password_verify($password, $password_u)){

到...

if(password_verify($password, html_entity_decode($password_u))){

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM