Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. *** INDEX.PHP ***
  2.  
  3. $query = "SELECT * FROM `users` WHERE username = '$username'";
  4. $result = mysql_query($query, $con);
  5. $row = mysql_fetch_row($result);                
  6. $num_rows = mysql_num_rows($result);
  7. $hashedpass = decryptpass($password, $row[4]);
  8.  
  9. if(!$num_rows || $num_rows < 1 ) {
  10.     $error = "Login Failed";
  11. } elseif($row[2] != $hashedpass) {
  12.     $error = "Invalid Password";
  13. } else {                        
  14.     // Login Successful! Set session variables
  15.     $_SESSION['loggedIn'] = true;
  16.     $_SESSION['username'] = $username;  
  17. }
  18.  
  19.  
  20. *** FUNCTIONS.PHP ***
  21.  
  22. function encryptpass($password) {
  23.     $SALT = time();
  24.     $SALTpass = $SALT.$SALT;
  25.     $hash = sha1(md5($SALTpass.$password.$SALTpass));
  26.     return $hash;
  27. }
  28.  
  29. function decryptpass($password, $dbpass) {
  30.     $SALTpass = $dbpass.$dbpass;
  31.     $hash = sha1(md5($SALTpass.$password.$SALTpass));
  32.     return $hash;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement