Guest User

Untitled

a guest
May 30th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. //retreive our data from post(from RegisterHtml.php)
  4. $username = $_POST['username'];
  5. $pass1 = $_POST['pass1'];
  6. $pass2 = $_POST['pass2'];
  7.  
  8. if($pass1 != $pass2){
  9.  
  10. echo "Passwords do not match";
  11. die();
  12. }
  13. //echo "Passwords do not match";
  14.  
  15. if(strlen($username) > 30){
  16.  
  17. echo "Username must be under 30 characters";
  18. die();
  19. //echo "Username cannot be more than 30 characters long";
  20. }
  21.  
  22. $hash = hash('sha256', $pass1); //hash the file with sha256 algorithm
  23.  
  24. //creates a 3 character sequence
  25. function createSalt()
  26. {
  27. $string = md5(uniqid(rand(), true));
  28. return substr($string, 0, 3);
  29. }
  30. $salt = createSalt();
  31. $hash = hash('sha256', $salt . $hash);
  32.  
  33. //database portion
  34. $dbhost = 'localhost';
  35. $dbname = 'login';
  36. $dbuser = 'chris';
  37. $dbpass = '';
  38. $conn = mysql_connect($dbhost,$dbuser,$dbpass);
  39. mysql_select_db($dbname, $conn);
  40.  
  41. //sanitize username
  42. $username = mysql_real_escape_string($username); //helps prevent mysql injections
  43. $query = "INSERT INTO users (username, password, salt)
  44. VALUES ('$username', '$hash', '$salt');";
  45. mysql_query($query);
  46. mysql_close();
  47.  
  48. header('Location: loginHtml.php'); //direct user to loginHtml.php
  49.  
  50. echo "Registry Successful";
  51. ?>
Add Comment
Please, Sign In to add comment