Advertisement
MadScientist2010

7852396541

Nov 26th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php session_start(); ob_start();
  2.  
  3. //ob_start();
  4. //########################################################
  5. //################ DATABASE CREDENTIALS #################
  6. $dbusername="dbuser";
  7. $dbpassword="HFqJdX3MxJfyr34c";
  8. $database="sad";
  9. //########################################################
  10.  
  11. //connects database
  12. $con = mysql_connect("localhost",$dbusername,$dbpassword);
  13. if (!$con)
  14. {
  15. die('Could not connect: ' . mysql_error());
  16. }
  17. $selected = mysql_select_db($database,$con) or die("Cannot use database");
  18.  
  19. $timeout = 25; // Number of seconds until it times out.
  20. // Check if the timeout field exists.
  21. if(isset($_SESSION['timeout'])) {
  22. // See if the number of seconds since the last
  23. // visit is larger than the timeout period.
  24. $duration = time() - (int)$_SESSION['timeout'];
  25. if($duration > $timeout) {
  26. // Destroy the session and restart it.
  27. unset($_SESSION['loginAttempt']);
  28. }
  29. }
  30. // Update the timeout field with the current time.
  31. $_SESSION['timeout'] = time();
  32.  
  33. function logout()
  34. {
  35. session_destroy();
  36. session_start();
  37. header('Location: ./index.php');
  38.  
  39. }
  40.  
  41. function registerAccount($usern,$passw,$level)
  42. {
  43. $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
  44. $salt ="";
  45. for ($i = 0; $i < 6; $i++) {
  46. $salt .= $characters[rand(0, strlen($characters) - 1)];
  47. }
  48.  
  49. $passhash = md5(sha1(md5($passw.$salt)));
  50. $query = mysql_query("INSERT INTO account(userName,password,salt,userLevel) VALUES ('".$usern."', '".$passhash."', '".$salt."','$level')");
  51.  
  52. }
  53.  
  54. function checkUser($user)
  55. {
  56. $query = mysql_query("select * from account where userName = '$user'");
  57. $result = mysql_num_rows($query);
  58. if($result>0){return true;} else{return false;}
  59. }
  60.  
  61. function login($usern,$passw)
  62. {
  63. $query = mysql_query("select * from account where userName = '$usern'");
  64. while($row = mysql_fetch_array($query))
  65. {
  66. $salt = $row['salt'];
  67. $confirm =$row['password'];
  68. }
  69.  
  70. if ($confirm == (md5(sha1(md5($passw.$salt)))))
  71. {return true;}else{return false;}
  72. }
  73. function sessionBegin($usern)
  74. {
  75. $query = mysql_query("select * from account where userName = '$usern'");
  76. while($row = mysql_fetch_array($query))
  77. {
  78. $_SESSION['username']=$usern;
  79. $_SESSION['userlevel']=$row['userLevel'];
  80. }
  81. $query2 = mysql_query("select * from member where membershipID = '$_SESSION[username]'") or die (mysql_error());
  82. while($q2=mysql_fetch_array($query2))
  83. {
  84. $_SESSION['name'] = $q2['lastName'].', '.$q2['firstName'].', '.$q2['middleName'];
  85. }
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement