Guest User

Untitled

a guest
Jun 23rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2.  
  3. //retreive our data from post(from Register.php)
  4. $username = $_POST['username'];
  5. $pass1 = $_POST['pass1'];
  6. $pass2 = $_POST['pass2'];
  7. $emailadd = $_POST['emailAdd'];
  8. $uniref = $_POST['uref'];
  9. $centerID = $_POST['centerID'];
  10.  
  11. //validation
  12. if ((!$username) || (!$pass1) || (!$pass2) || (!$emailAdd) || (!$uniquereference)|| (!$centerID) ){
  13.  
  14.         $errorMsg = '<u>Error:</u> You did not submit the following credential(s) correctly: <br/>';
  15.        
  16.         if(!$username){
  17.             $errorMsg .= ' Username<br/>';
  18.         }
  19.         if(!$pass1){
  20.             $errorMsg .= ' Password 1<br/>';
  21.         }
  22.         if(!$pass2){
  23.             $errorMsg .= ' Password 2<br/>';
  24.         }
  25.         if(!$emailadd){
  26.             $errorMsg .= ' Email Address<br/>';
  27.         }
  28.         if(!$uniquereference){
  29.             $errorMsg .= ' Unique Reference<br/>';
  30.         }
  31.         if(!$centerID){
  32.             $errorMsg .= ' Centre ID<br/>';
  33.         }
  34.         else if($pass1 != $pass2){
  35.             $errorMsg = "<u>ERROR:</u><br />Your Passwords do not match.<br />";
  36.         }
  37.         else if (strlen($username) < 4) {
  38.             $errorMsg = "<u>ERROR:</u><br />Your User Name is too short. 4 - 20 characters please.<br />";
  39.         }
  40.         else if (strlen($username) > 20) {
  41.             $errorMsg = "<u>ERROR:</u><br />Your User Name is too long. 4 - 20 characters please.<br />";
  42.         }
  43. }
  44.  
  45. $hash = hash('sha256', $pass1); //hash the file with sha256 algorithm
  46.  
  47. //creates a 3 character sequence
  48. function createSalt()
  49. {
  50.     $string = md5(uniqid(rand(), true));
  51.     return substr($string, 0, 3);
  52. }
  53. $salt = createSalt();
  54. $hash = hash('sha256', $salt . $hash);
  55.  
  56. //database portion
  57. $dbhost = 'localhost';
  58. $dbname = 'login';
  59. $dbuser = 'chris';
  60. $dbpass = '';
  61. $conn = mysql_connect($dbhost,$dbuser,$dbpass);
  62. mysql_select_db($dbname, $conn);
  63.  
  64. //sanitize fields
  65. $username = mysql_real_escape_string($username); //helps prevent mysql injection
  66.  
  67. $query = "INSERT INTO users (username, password, emailadd, salt, uniref, centerID)
  68.     VALUES ('$username', '$hash', '$salt', '$emailadd', '$uniref', '$centerID');";
  69.    
  70. mysql_query($query);
  71. mysql_close();
  72.  
  73. header('Location: Registry.php'); //direct user to loginHtml.php
  74.  
  75. echo "Registry Successful";
  76. ?>
Add Comment
Please, Sign In to add comment