I want to know what the best way is to secure passwords.
Currently I md5 the password, then hash it with sha256, it that good enough? Would YOU sign up for something with that sort of security.
Thanks, Mitchfizz05.
$salt = hash("sha256",mcrypt_create_iv(64));
// and then encrypt the password
$encrypted = hash("sha256", $inputPass . $salt)
<?php
// make sure we can redirect (this was just a nice little function that made redirects nicer to user over and over)
// for your case you would most likely use die("why it died") so that the browser gets the error, and computercraft gets the error message
// so that you can tell your user why the registration failed
// NOTE: the scripts at the other end are designed to receive a GET, which is why the redirects are formatted in the way they are (plus its easier to do GET than POST from PHP)
require_once($_SERVER['DOCUMENT_ROOT'] . "eta/functions/redirect.php");
if (!isset($_POST['rpass'])){ redirect('index.php?e'); }
// The salt is just a bunch of random data to help further hide the hashed password and make it harder to do a lookup on the hashed password
// each user has a different salt so that even two passwords if the same, have different hashed values
$salt = hash("sha256",mcrypt_create_iv(64));
// get the register details from the post data
$input_username = urldecode($_POST["user"]);
$input_email = urldecode($_POST["email"]);
$input_password = urldecode($_POST["pass"]);
$input_repeat_password = urldecode($_POST["rpass"]);
// deleted variable validation... not needed for this example to you Thib0704
// create a new mysql connection
$connection = new mysqli($db_host, $db_user, $db_pass, $db_name);
// make sure there is a connection
if (mysqli_connect_error()) { redirect('register.php?d'); }
// create a prepared statement to check if the username exists already, the ? is where values will end up going
$query = "SELECT COUNT(username) FROM user WHERE username = ?;";
// create the statement
$stmt = $connection->prepare($query);
// fill in the blanks that were in the query, i.e. place the username in the ? ... s means string, there are other letters for other data types
$stmt->bind_param("s", $input_username);
// check if the execution succeeded
if (!$stmt->execute()){ redirect('register.php?d'); }
// bind the returned data to variables, this gets the return result from the database and adds it into the $usersWithThatName variable
$stmt->bind_result($usersWithThatName);
// complete the process
$stmt->fetch();
// make sure no other users have the same username
if($usersWithThatName != 0){ redirect('register.php?x'); }
// close the mysql statement, don't close the connection, we have more to do still
$stmt->close();
// create a prepared statement to make sure the email hasn't been used before, the process is exactly the same as above
$query = "SELECT COUNT(email) FROM user WHERE email = ?;";
$stmt = $connection->prepare($query);
$stmt->bind_param("s", $input_email);
if (!$stmt->execute()){ redirect('register.php?d'); }
$stmt->bind_result($usersWithThatEmail);
$stmt->fetch();
if($usersWithThatEmail != 0){ redirect('register.php?l'); }
$stmt->close();
// append the salt to the input password and then hash it, making sure to use the same hashing algorithm otherwise the weakest link is the lower hash algo
$hashed_password = hash("sha256", $input_password . $salt);
// create a prepared statement to insert many variables into the table (we have to insert the salt so we can know what the users salt is later)
$insert_stmt = "INSERT INTO user (username, password, salt, email, securityLevel) VALUES(?, ?, ?, ?, 1);";
$stmt = $connection->prepare($insert_stmt);
// now notice that we have an 's' per ?, so for each ? you must have a value to put into it, again this is a bad example because all we used were varchar2 everywhere
// as that was all we needed to use, but there are other letters for other data types
$stmt->bind_param("ssss", $input_username, $hashed_password, $salt, $input_email);
if (!$stmt->execute()){ redirect('register.php?d'); }
// I left this in just so you could see that you can get the primary key of the result, in this case for us it was a number as the unique user id and we then made
// a folder for them on the server
$userId = $connection->insert_id;
mkdir($_SERVER['DOCUMENT_ROOT'] . 'eta/user_data/' . $userId);
// this line takes us back to a page, but below the closing php tag you could just have html code like "registration successful" and that is:
// 1 what the browser will show and
// 2 the only text computercraft will get back
redirect('index.php?s');
?>
It won't be safe at all…I md5 the password,
It won't be safe at all…I md5 the password,
MD5 is actually much worse than SHA256. It is not just about how they can be compromised by a rainbow table, but it is also about the amount of collisions in the hashes.md5 isn't the tell of bad security. md5 isn't too much worse than sha256 because they can both be compromised by a rainbow table, although md5 is much more discovered by now.
As I stated above, this actually reduces entropy, not increases it… The hash is only as strong as its weakest link…But doubling up with two like OP said would help an awful lot
local last = password
for i=1,1000 do
last = sha2(last..salt)
end
return last
You use Lua on your website? o.O and yes, it's a little extreme, it doesn't increase entropy, but it doesn't decrease it either.I use on my website something like this:local last = password for i=1,1000 do last = sha2(last..salt) end return last
It's a bit too much tho :P/>