Guest User

full login.php

a guest
Sep 13th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. require_once 'engine/config.php';
  5. require 'engine/functions.php';
  6.  
  7. $user = new user();
  8.  
  9.  
  10. function generateRandomString($length = 10) {
  11. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  12. $charactersLength = strlen($characters);
  13. $randomString = '';
  14. for ($i = 0; $i < $length; $i++) {
  15. $randomString .= $characters[rand(0, $charactersLength - 1)];
  16. }
  17. return $randomString;
  18. }
  19. ?>
  20. <!doctype html>
  21. <!--[if lte IE 9]> <html class="lte-ie9" lang="en"> <![endif]-->
  22. <!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]-->
  23. <head>
  24. <meta charset="UTF-8">
  25. <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
  26. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  27.  
  28. <link rel="icon" type="image/png" href="assets/img/favicon-16x16.png" sizes="16x16">
  29. <link rel="icon" type="image/png" href="assets/img/favicon-32x32.png" sizes="32x32">
  30.  
  31. <title>Project - Login Page</title>
  32.  
  33. <link href='http://fonts.googleapis.com/css?family=Roboto:300,400,500' rel='stylesheet' type='text/css'>
  34.  
  35. <!-- uikit -->
  36. <link rel="stylesheet" href="bower_components/uikit/css/uikit.almost-flat.min.css"/>
  37.  
  38. <!-- altair admin login page -->
  39. <link rel="stylesheet" href="assets/css/login_page.min.css" />
  40.  
  41. </head>
  42. <?php
  43.  
  44.  
  45. if (!($user -> LoggedIn()))
  46. {
  47. if (isset($_POST['loginBtn']))
  48. {
  49. $username = $_POST['username'];
  50. $password = $_POST['passwd'];
  51. $errors = array();
  52. if (empty($username) || empty($password))
  53. {
  54. $errors[] = 'Please enter your username and password.';
  55. }
  56. if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
  57. {
  58. $errors[] = 'Username must be 4-15 characters and alphanumeric only!';
  59. }
  60.  
  61. if (empty($errors))
  62. {
  63. $sha = hash("sha512", $password);
  64. $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
  65. $SQLCheckLogin -> execute(array(':username' => $username, ':password' => $sha));
  66. $countLogin = $SQLCheckLogin -> fetchColumn(0);
  67. if ($countLogin == 1)
  68. {
  69. $SQLGetInfo = $odb -> prepare("SELECT `username`, `ID`,`status` FROM `users` WHERE `username` = :username AND `password` = :password");
  70. $SQLGetInfo -> execute(array(':username' => $username, ':password' => $sha));
  71. $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
  72. $status = $userInfo['status'];
  73. $userid = $userInfo['ID'];
  74. $userip = $_SERVER['REMOTE_ADDR'];
  75. if ($status == 1)
  76. {
  77. echo '<div class="alert alert-block alert-danger fade in"><button type="button" class="close close-sm" data-dismiss="alert"><i class="fa fa-times"></i></button><strong>Oops!</strong> Your account has been banned.</div>';
  78. }
  79. elseif ($status == 0)
  80. {
  81. $username = $userInfo['username'];
  82.  
  83. $_SESSION['username'] = $userInfo['username'];
  84. $_SESSION['ID'] = $userInfo['ID'];
  85. $_SESSION['wsource'] = generateRandomString();
  86. echo '<center><div class="uk-alert uk-alert-success" data-uk-alert>
  87. <a href="#" class="uk-alert-close uk-close"></a>
  88. Successfully logged in , Redirecting...
  89. </div><meta http-equiv="refresh" content="3;url=index.php"></center>';
  90. }
  91. }
  92. else
  93. {
  94. echo '<center><div class="uk-alert uk-alert-danger" data-uk-alert>
  95. <a href="#" class="uk-alert-close uk-close"></a>
  96. Incorrect Username or Password.
  97. </div></center>';
  98. }
  99. }
  100. else
  101. {
  102. echo '<center><div class="uk-alert uk-alert-danger" data-uk-alert>
  103. <a href="#" class="uk-alert-close uk-close"></a>
  104. Oops!
  105. </div><br /></center>';
  106. foreach($errors as $error)
  107. {
  108. echo '- '.$error.'<br />';
  109. }
  110. echo '</div>';
  111. }
  112. }
  113. }
  114. else
  115. {
  116. header('location: index.php');
  117. }
  118.  
  119. ?>
  120. <body class="login_page">
  121.  
  122. <div class="login_page_wrapper">
  123. <div class="md-card" id="login_card">
  124. <div class="md-card-content large-padding" id="login_form">
  125. <div class="login_heading">
  126. <div class="user_avatar"></div>
  127. </div>
  128. <form action="login.php" method="post">
  129. <div class="uk-form-row">
  130. <label for="login_username">Username</label>
  131. <input class="md-input" type="text" id="login_username" name="username" />
  132. </div>
  133. <div class="uk-form-row">
  134. <label for="login_username">Password</label>
  135. <input class="md-input" type="password" id="login_username" name="passwd" />
  136. </div>
  137. <div class="uk-margin-medium-top">
  138. <button class="md-btn md-btn-primary md-btn-block md-btn-large" name="loginBtn">Sign In</button>
  139. </div>
  140. <div class="uk-margin-top">
  141. <span class="icheck-inline">
  142. <input type="checkbox" name="login_page_stay_signed" id="login_page_stay_signed" data-md-icheck />
  143. <label for="login_page_stay_signed" class="inline-label">Stay signed in</label>
  144. </span>
  145. </div>
  146. </form>
  147. </div>
  148. <div class="md-card-content large-padding uk-position-relative" id="login_help" style="display: none">
  149. <button type="button" class="uk-position-top-right uk-close uk-margin-right uk-margin-top" id="login_help_close"></button>
  150. <h2 class="heading_b uk-text-success">Can't log in?</h2>
  151. <p>Here’s the info to get you back in to your account as quickly as possible.</p>
  152. <p>First, try the easiest thing: if you remember your password but it isn’t working, make sure that Caps Lock is turned off, and that your username is spelled correctly, and then try again.</p>
  153. <p>If your password still isn’t working, it’s time to <a href="#" id="login_password_reset_show">reset your password</a>.</p>
  154. </div>
  155. <div class="md-card-content large-padding" id="login_password_reset" style="display: none">
  156. <h2 class="heading_a uk-margin-large-bottom">Reset password</h2>
  157. <form action="">
  158. <div class="uk-form-row">
  159. <label for="login_email_reset">Your email address</label>
  160. <input class="md-input" type="text" id="login_email_reset" name="login_email_reset" />
  161. </div>
  162. <div class="uk-margin-medium-top">
  163. <button class="md-btn md-btn-primary md-btn-block">Reset password</button>
  164. </div>
  165. </form>
  166. </div>
  167. </div>
  168. <div class="uk-margin-top">
  169. <a href="#" id="login_help_show">Need help?</a>
  170. </div>
  171. </div>
  172.  
  173. <!-- common functions -->
  174. <script src="assets/js/common.min.js"></script>
  175. <!-- altair core functions -->
  176. <script src="assets/js/altair_admin_common.min.js"></script>
  177.  
  178. <!-- altair login page functions -->
  179. <script src="assets/js/pages/login_page.min.js"></script>
  180.  
  181. </body>
  182. </html>
Add Comment
Please, Sign In to add comment