Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ($_POST['submit'])
- {
- //retrieve our data from POST
- $username = $_POST['username'];
- $pass1 = $_POST['pass1'];
- $pass2 = $_POST['pass2'];
- if($pass1 != $pass2)
- {
- print "Passwords did not match.";
- }
- else
- {
- if(strlen($username) > 30)
- {
- print "Passwords can not be more then 30 characters long.";
- }
- else
- {
- $hash = hash('sha256', $pass1);
- //creates a 3 character sequence
- function createSalt()
- {
- $string = md5(uniqid(rand(), true));
- return substr($string, 0, 3);
- }
- $salt = createSalt();
- $hash = hash('sha256', $salt . $hash);
- $dbhost = '';
- $dbname = '';
- $dbuser = '';
- $dbpass = ''; //not really
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- mysql_select_db($dbname, $conn);
- //sanitize username
- $username = mysql_real_escape_string($username);
- $query = "INSERT INTO users ( username, hash, salt )
- VALUES ( '$username' , '$hash' , '$salt' );";
- mysql_query($query);
- mysql_close();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement