ユーザーがウェブサイト上のアカウントに登録できる登録スクリプトを作成しています。私はsha256を使ってパスワードを暗号化することに決めました。sha256暗号化を使用したPHP登録スクリプト
// Set error message as blank upon arrival to page
$errorMsg = "";
// First we check to see if the form has been submitted
if (isset($_POST['Submit'])){
//Connect to the database through our include
require_once ('includes/connect.inc.php');
// Filter the posted variables
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = stripslashes($_POST['email']);
$password = preg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
$email = strip_tags($email);
$town = preg_replace("[^A-Z a-z0-9]", "", $_POST['town']); // filter everything but spaces, numbers, and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$forename) || (!$surname) || (!$email) || (!$password) || (!$town)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$forename){
$errorMsg .= "--- Forename";
} else if(!$surname){
$errorMsg .= "--- Surname";
} else if(!$email){
$errorMsg .= "--- email";
} else if(!$password){
$errorMsg .= "--- password";
} else if(!$town){
$errorMsg .= "--- town";
}
} else {
$hash = hash("sha256", $password);
$sql = "INSERT INTO customers (forename, surname, email, password, town, registeredDate, active)
VALUES('$forename','$surname','$email', '$hash', '$town', GETDATE(), 'True')" ;
$stmt2 = sqlsrv_query($conn,$sql);
} // Close else after missing vars check
} //Close if $_POST
?>
<form action="join_form.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="2"><font color="#FF0000"><?php echo "$errorMsg"; ?></font></td>
</tr>
<tr>
<td width="163"><div align="right">Forename:</div></td>
<td width="409"><input name="forename" type="text"/></td>
</tr>
<tr>
<td width="163"><div align="right">Surname:</div></td>
<td width="409"><input name="surname" type="text"/></td>
</tr>
<tr>
<td><div align="right">Email: </div></td>
<td><input name="email" type="text" /></td>
</tr>
<tr>
<td><div align="right"> Password: </div></td>
<td><input name="password" type="password" />
<font size="-2" color="#006600">(letters or numbers only, no spaces no symbols)</font></td>
</tr>
<tr>
<td><div align="right">Town: </div></td>
<td>
<input name="town" type="text" />
</td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit" value="Submit Form" /></td>
</tr>
</form>
が、私は何も起こりません[送信]ボタンを押したとき:
は、ここに私のコードです。エラーメッセージは表示されませんが、レコードはデータベースに追加されません。
私はそれはたぶん私は間違った場所か何かでそれを置く
$hash = hash("sha256", $password);
を使用して、私とは何かを持って知っていますか? 私はPHPを初めて使っています。
されていませんパスワード。 http://stackoverflow.com/a/10471744/34397 – SLaks
**パスワードに許可されていない文字は_!** **特に決して黙ってはいけません。 – SLaks
SQLインジェクションの脆弱性が存在します。 – SLaks