php mysqli不识别,不识别数据库PHP MYSQLi中的密码
我有一個注冊表單,允許用戶創建用戶名和密碼,然后存儲在數據庫中.
//values to be inserted in database table
//session_start();
include('connect.php');
//Fixed cost of 10 to fit server req
//Random salt to be added to the pass
$options = [
'cost' => 10,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
$email = $_POST['email'];
$password= password_hash($_POST['password'], PASSWORD_BCRYPT, $options);
$username= $_POST['username'];
$query = "INSERT INTO users (username, email, password) VALUES(?, ?, ?)";
$statement = $mysqli->prepare($query);
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('sss', $username, $email, $password);
if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'
';
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
?>
這是我的腳本,用于檢查用戶輸入的用戶名和密碼是否存在.
include 'connect.php';
if ( !isset($_POST['username'], $_POST['password']) ) {
// Could not get the data that should have been sent.
die ('Username and/or password does not exist!');
}
// Prepare our SQL
if ($stmt = $mysqli->prepare('SELECT password FROM users WHERE username = ?')) {
// Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
$stmt->bind_param('s', $_POST['username']);
$stmt->execute();
$stmt->store_result();
// Store the result so we can check if the account exists in the database.
if ($stmt->num_rows > 0) {
$stmt->bind_result($password);
$stmt->fetch();
// Account exists, now we verify the password.
if (password_verify($_POST['password'], $password)) {
// Verification success! User has loggedin!
echo 'You have logged in!';
} else {
echo 'Incorrect username and/or password!';
}
} else {
echo 'Incorrect username blar password!';
}
$stmt->close();
} else {
echo 'Could not prepare statement!';
}
?>
它輸出的用戶名和/或密碼不正確,所以我假設問題在于我在注冊系統中對密碼進行了哈希處理,或者它是否只是找不到我正在尋找的詳細信息.
HTML表格:
Enter your username and password to sign in
Username*
Password *
Forgot your password?
Click here
解決方法:
type =“username”不是有效的表單元素類型.
將其更改為type =“text”
但是,我之前在評論中提到過:
type=”username” use type=”text” – Fred -ii- 20 mins ago
>我確實說“使用”而不是“嘗試”;-)
您可能認為“用戶名”類型是HTML5語法;事實并非如此.
要查看有效的HTML5輸入類型列表,請參閱以下鏈接:
從W3.org頁面中拉出:
input元素是用于表示輸入控件的多用途元素.
以下各節介紹了input元素的詳細信息:
>輸入類型=文本
>輸入類型=密碼
>輸入類型=復選框
>輸入類型=無線電
>輸入類型=按鈕
>輸入類型=提交
>輸入類型=重置
>輸入類型=文件
>輸入類型=隱藏
>輸入類型=圖像
>輸入類型=日期時間新
>輸入類型=日期時間 – 本地新
>輸入類型=日期新
>輸入類型=月新
>輸入類型=時間新
>輸入類型=周新
>輸入類型=數字新
>輸入類型=范圍NEW
>輸入類型=電子郵件新
>輸入類型=網址新
>輸入類型=搜索新
>輸入類型= tel NEW
>輸入類型=顏色新
關于在您的密碼列中使用varchar(60)并從password_hash()手冊中提取的旁注:
PASSWORD_DEFAULT – 使用bcrypt算法(默認自PHP 5.5.0起).請注意,此常量旨在隨著時間的推移而變化,因為新的和更強大的算法被添加到PHP中.因此,使用此標識符的結果長度可能會隨時間而變化.因此,建議將結果存儲在數據庫列中,該列可以擴展到超過60個字符(255個字符將是一個不錯的選擇).
標簽:php,login
來源: https://codeday.me/bug/20190727/1557494.html
總結
以上是生活随笔為你收集整理的php mysqli不识别,不识别数据库PHP MYSQLi中的密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 忍者大师晓鼬最强阵容是什么
- 下一篇: 三清境前山4个隐藏任务是什么