Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start(); ob_start();
- //ob_start();
- //########################################################
- //################ DATABASE CREDENTIALS #################
- $dbusername="dbuser";
- $dbpassword="HFqJdX3MxJfyr34c";
- $database="sad";
- //########################################################
- //connects database
- $con = mysql_connect("localhost",$dbusername,$dbpassword);
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- $selected = mysql_select_db($database,$con) or die("Cannot use database");
- $timeout = 25; // Number of seconds until it times out.
- // Check if the timeout field exists.
- if(isset($_SESSION['timeout'])) {
- // See if the number of seconds since the last
- // visit is larger than the timeout period.
- $duration = time() - (int)$_SESSION['timeout'];
- if($duration > $timeout) {
- // Destroy the session and restart it.
- unset($_SESSION['loginAttempt']);
- }
- }
- // Update the timeout field with the current time.
- $_SESSION['timeout'] = time();
- function logout()
- {
- session_destroy();
- session_start();
- header('Location: ./index.php');
- }
- function registerAccount($usern,$passw,$level)
- {
- $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $salt ="";
- for ($i = 0; $i < 6; $i++) {
- $salt .= $characters[rand(0, strlen($characters) - 1)];
- }
- $passhash = md5(sha1(md5($passw.$salt)));
- $query = mysql_query("INSERT INTO account(userName,password,salt,userLevel) VALUES ('".$usern."', '".$passhash."', '".$salt."','$level')");
- }
- function checkUser($user)
- {
- $query = mysql_query("select * from account where userName = '$user'");
- $result = mysql_num_rows($query);
- if($result>0){return true;} else{return false;}
- }
- function login($usern,$passw)
- {
- $query = mysql_query("select * from account where userName = '$usern'");
- while($row = mysql_fetch_array($query))
- {
- $salt = $row['salt'];
- $confirm =$row['password'];
- }
- if ($confirm == (md5(sha1(md5($passw.$salt)))))
- {return true;}else{return false;}
- }
- function sessionBegin($usern)
- {
- $query = mysql_query("select * from account where userName = '$usern'");
- while($row = mysql_fetch_array($query))
- {
- $_SESSION['username']=$usern;
- $_SESSION['userlevel']=$row['userLevel'];
- }
- $query2 = mysql_query("select * from member where membershipID = '$_SESSION[username]'") or die (mysql_error());
- while($q2=mysql_fetch_array($query2))
- {
- $_SESSION['name'] = $q2['lastName'].', '.$q2['firstName'].', '.$q2['middleName'];
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement