<?php
require('login_include_connection.php');
if (isset($_POST['btn_confirm'])) {
$user_name=$_POST['user_name'];
$user_password=sha1($_POST['user_password']);
if (empty($user_name) || empty($user_password)) {
#This validation works only if user place user name, leaving blank password will still works which is not ok
echo "Please make corect inputs!!!"; #Both fields must have inputs
} else {
$sql="INSERT into user_info (id, user_name, user_password) VALUES (null, '$user_name', '$user_password')";
$result=mysqli_query($conn, $sql); #Proceed with sql query and place record to MySQL database
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body {
background-color: lightblue;
}
</style>
</head>
<body>
<h2>User registration</h2>
<form method="POST" action="sesija_registracija.php">
<input type="text" name="user_name">
<input type="password" name="user_password">
<input type="submit" name="btn_confirm" value="REGISTER USER NOW">
</form>
</body>
</html>
前の質問に間違いがあります。したがって、基本的な登録PHPスクリプトがあります。ユーザー名とパスワードを入力する必要があります。パスワードの値がなくても、私のフォームはデータベースにユーザー名を入れます。だから、if文で何が間違っているのですか?empty()
はsha1()
などとは動作しません。私が欲しいのは、ユーザーが両方のフィールドに記入する必要があることを確認することだけです。ハッシュsha1()でのユーザーのパスワード検証は機能しません。
**危険**:不適切なハッシングアルゴリズム(http://php.net/manual/en/faq.passwords.php)を使用しており、[注意を払う]必要があります(https:// www.owasp.org/index.php/Password_Storage_Cheat_Sheet)にユーザーのパスワードを入力します。 – Quentin
**危険**:[SQLインジェクション攻撃](http://bobby-tables.com/)に脆弱** ** [防御]する必要があります(http://stackoverflow.com/questions/ 60174/best-way-to-prevent-sql-injection-in-php)をご利用ください。 – Quentin
挿入の直前のelse節に '$ user_password = sha1($ _ POST ['user_password']);を適用してください。最初の割り当てからsha1を削除します。それはあなたの期待どおりに動作します。 sha256以上を使用してください。[password_hash](http://php.net/manual/en/function.password-hash.php) –