Advertisement
Guest User

Prova

a guest
Dec 3rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. // userName and password sent from form
  2. $myusername=$_POST['username'];
  3. $mypassword=$_POST['password'];
  4.  
  5. // To protect MySQL injection (more detail about MySQL injection)
  6. $myusername = stripslashes($myusername);
  7. $mypassword = stripslashes($mypassword);
  8. $myusername = mysql_real_escape_string($myusername);
  9. $mypassword = mysql_real_escape_string($mypassword);
  10. $salt = createSalt();
  11. $hash = hash('sha256', $mypassword);
  12. $mypassword = hash('sha256', $salt . $hash);
  13.  
  14. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  15. $result=mysql_query($sql);
  16.  
  17. // Mysql_num_row is counting table row
  18. $count=mysql_num_rows($result);
  19.  
  20. // If result matched $myusername and $mypassword, table row must be 1 row
  21.  
  22. if($count==1 ){
  23.     if(crypt($password, $row['Password']) == $row['Password'])
  24.     {      
  25.         header("location:index.php");
  26.         exit();
  27.     }
  28. }
  29. else {
  30.     //echo "Wrong Username or Password";
  31.     header("Location:login.php?errorMssg=".urlencode("Wrong Username or Password"));
  32. }
  33.  
  34. function createSalt()
  35. {
  36.     return '2123293dsj2hu2besdbsjdsd';
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement