Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Longhorn Linux Member System - By Cuonic
- Uses MySQL Database. Interaction via MySQLi
- Enables Login and displaying user info on site
- */
- session_start();
- include("mysql.php"); // MySQL Connection. Establishes connection successfully
- // Function defining :
- function randstr()
- {
- $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $randstring = '';
- for ($i = 0; $i <= 15; $i++)
- {
- $randstring = $characters[rand(0, strlen($characters))];
- }
- return $randstring;
- }
- // Error / Success message array defining :
- $errormsg = array();
- $successmsg = array();
- if($_REQUEST['action'])
- {
- $action = $_REQUEST['action'];
- switch($action)
- {
- case '1' :
- $username = $_REQUEST['username'];
- $password = $_REQUEST['password'];
- if(strlen($username) == 0) { $errormsg[] = "Username field is empty !"; }
- elseif(strlen($username) > 30) { $errormsg[] = "Username is too long !"; }
- elseif(strlen($username) < 3) { $errormsg[] = "Username is too short !"; }
- if(strlen($password) == 0) { $errormsg[] = "Password field is empty !"; }
- elseif(strlen($password) > 30) { $errormsg[] = "Password is too long !"; }
- elseif(strlen($password) < 5) { $errormsg[] = "Password is too short !"; }
- if(count($errormsg) == 0)
- {
- $password = hash("SHA512", $password);
- $query = $mysqli->prepare("SELECT password FROM users WHERE username=?");
- $query->bind_param("s", $username);
- $query->execute();
- $query->bind_result($db_password);
- $query->fetch();
- $count = $query->num_rows;
- if($count == 0) { $errormsg[] = "Username is incorrect !"; } // gets to here, no rows detected for correct username D:
- else
- {
- if($password == $db_password)
- {
- $_SESSION['isauth'] = 1;
- $_SESSION['username'] = $username;
- }
- else
- {
- $errormsg[] = "Password is incorrect !";
- }
- }
- }
- break;
- default :
- $errormsg[] = "Invalid Action ID !";
- break;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement