Advertisement
Guest User

Untitled

a guest
Mar 31st, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1.     public function init() {
  2.        return new DatabaseManager('localhost','root','49254975','yumenet');
  3.     }
  4.     public function login(){
  5.         if(isset($_POST['username'], $_POST['password'])) {
  6.             if (empty($_POST['username']) && empty($_POST['password'])) {
  7.                 echo '<div id="alert">Bitte f&uuml;lle alle Felder aus!</div>';
  8.             } else {
  9.                 $username = $_POST['username'];
  10.                 $password = $_POST['password'];
  11.                 $db = self::init()->getOut("SELECT * FROM yume_users WHERE username = '" . $username . "' AND password = '".sha1($password)."'");
  12.                 $db->execute();
  13.                 $output = $db->fetchObject();
  14.                 if ($output->username == $username && $output->password == sha1($password)) {
  15.                     $_SESSION['username'] = $output->username;
  16.                     $_SESSION['password'] = $output->password;
  17.                     $_SESSION['token'] = rand(1000, 20);
  18.                     header('Location: ./dashboard');
  19.                 } else {
  20.                     echo '<div id="alert">Benutzername oder Passwort falsch</div>';
  21.                 }
  22.             }
  23.         }
  24.     }
  25.     public function register(){
  26.         if(isset($_POST['re_username'], $_POST['re_password'], $_POST['re_password2'], $_POST['re_email'])) {
  27.             if (empty($_POST['re_username']) && empty($_POST['re_password']) && empty($_POST['re_password2']) && empty($_POST['re_email'])) {
  28.                 echo '<div id="alert">Bitte f&uuml;lle alle Felder aus!</div>';
  29.             } else {
  30.                 $username = $_POST['re_username'];
  31.                 $password = $_POST['re_password'];
  32.                 $db = self::init()->getOut("SELECT * FROM yume_users WHERE username = '" . $username . "'");
  33.                 $db->execute();
  34.                 $output = $db->fetchObject();
  35.                 if($output->num_rows > 0 ){
  36.                     echo '<div class="error">Benutzername ist bereits vergeben!</div>';
  37.                 } else {
  38.                     $db = self::init()->getOut("INSERT INTO yume_users (username, password, avatar) VALUES ('".$username."', '".sha1($password)."', 'yume-32')");
  39.                     $db->execute();
  40.                     $_SESSION['username'] = $username;
  41.                     $_SESSION['token'] = rand(1000, 20);
  42.                     header('Location: /dashboard');
  43.                 }
  44.             }
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement