Advertisement
Guest User

Untitled

a guest
May 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author Linkero
  5.  * @copyright 2010
  6.  */
  7.  
  8. class login
  9. {
  10.     private $username;
  11.     private $password;
  12.     private $auth;
  13.  
  14.     public function beginLogin()
  15.     {
  16.         $regex = "@[^a-zA-Z0-9_-]+@i";
  17.         if (!preg_match($regex, $_POST['username'])) {
  18.             if (isset($_POST['login'])) {
  19.                 $username = $_POST['username'];
  20.                 if (strlen($username) < 3 || strlen($username) > 20) {
  21.                     echo "Username has to be between 3 and 20 characters";
  22.                 } else {
  23.                     login::checkPassword($_POST);
  24.                 }
  25.             }
  26.         } else {
  27.             echo "Username contains invalid characters.";
  28.         }
  29.     }
  30.     private function checkPassword($_POST)
  31.     {
  32.         $password = $_POST['password'];
  33.         if (strlen($password) < 6 || strlen($password) > 20) {
  34.             echo "Password has to be between 6 and 20 characters";
  35.         } else {
  36.             login::checkDBPassword($_POST);
  37.         }
  38.     }
  39.     private function checkDBPassword($_POST)
  40.     {
  41.         $query = 'SELECT * FROM users WHERE member_name = "' . $_POST['username'] . '"';
  42.         $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  43.         $auth = mysql_fetch_assoc($result) or die('Query failed: ' . mysql_error());
  44.         $dbmd5 = $auth['md5'];
  45.         $usermd5 = md5(base64_encode(md5(base64_encode($_POST['password']))));
  46.         if ($usermd5 != $dbmd5) {
  47.             echo "Invalid password. Try again.<br>";
  48.         } else {
  49.             login::setSession($auth, $_POST);
  50.         }
  51.     }
  52.     private function setSession($auth, $_POST)
  53.     {
  54.         $_SESSION['username'] = $auth['member_name'];
  55.         $_SESSION['md5'] = $auth['md5'];
  56.         $_SESSION['scroll'] = $auth['scroll'];
  57.         $_SESSION['mid'] = $auth['member_id'];
  58.         $_SESSION['gid'] = $auth['group_id'];
  59.         login::lastStep();
  60.     }
  61.     private function lastStep()
  62.     {
  63.         echo "Login Successful!";
  64.         echo '<script type="text/javascript">function goHome(){if (window.top!=window.self){window.top.location="index.php"}}</script>';
  65.         echo '<input type="button" onclick="goHome()" value="Click here to finish login!">';
  66.     }
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement