简体   繁体   English

PHP哈希密码中的注册脚本

[英]Registration script in php hashing passwords

I am learning PHP and am at a point where I have successfully managed to insert data into my database and it redirects me back to my registration form so I am happy at this point, I am just looking at ways to add the passwords into the database as a hash and to salt it it also. 我正在学习PHP,现在我已经成功地将数据插入数据库中,并且将我重定向回注册表单,因此我很高兴,在此我只是在寻找将密码添加到数据库中的方法。作为哈希,也可以对其加盐。

Where in my code do I begin doing this, I am not looking for an answer or somebody to do it for me I just need some advice. 我在我的代码中从哪里开始执行此操作,我不是在寻找答案或有人为我这样做,我只需要一些建议即可。

<?php

include 'connect.php';

// escape variables for security
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$first_name = mysqli_real_escape_string($con, $_POST['first_name']);
$last_name = mysqli_real_escape_string($con, $_POST['last_name']);
$email = mysqli_real_escape_string($con, $_POST['email']);

$sql="INSERT INTO users (username, password, first_name, last_name, email )
VALUES ('$username', '$password', '$first_name', '$last_name', '$email')";


if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}
    header ('Location: /register.php');



?>

You can use password_hash to hash your password. 您可以使用password_hash来哈希您的密码。

It will use the best algorithm available and be upgraded in the future. 它将使用现有的最佳算法,并在将来进行升级。

More infos here. 更多信息在这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM