Guest User

Untitled

a guest
Jan 8th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. require "/functions.php";
  2.  
  3. if (isset($_GET['user'])) {
  4. $user = $_GET['user'];
  5. }
  6. if (isset($_GET['key']) && (strlen($_GET['key']) == 32)){
  7. $key = $_GET['key'];
  8. }
  9.  
  10. if (isset($user) && isset($key)) {
  11. $sql = <<<SQL
  12. UPDATE users
  13. SET validation = NULL
  14. WHERE username='$user'
  15. AND validation='$key',
  16. user_group = 'member'
  17. SQL;
  18.  
  19. $count = $db->affected_rows;
  20.  
  21. if ($count == 1)
  22. {
  23. echo '<div>Your account is now active. You may now <a href="login.php">Log in</a></div>';
  24.  
  25. } else {
  26. echo '<div>Oops! Your account could not be activated. Please recheck the link or contact the system administrator.</div>';
  27.  
  28. }
  29. ob_end_flush();
  30.  
  31. } else {
  32. echo '<div>Error Occured .</div>';
  33. }
  34.  
  35. ?>
  36.  
  37. // Globals & error variable
  38. require "/functions.php";
  39.  
  40. session_start();
  41. $error = "";
  42.  
  43. if (isset( $_POST['Submit'])) {
  44. if (empty($_POST['username']) || empty($_POST['password'])) {
  45. $error = "Please fill in all fields!";
  46. }
  47. else {
  48.  
  49. $username=$_POST['username'];
  50. $password=$_POST['password'];
  51.  
  52. // Injection-protection!
  53. $username = stripslashes($username);
  54. $password = stripslashes($password);
  55. $username = mysqli_real_escape_string($db, $username);
  56. $password = mysqli_real_escape_string($db, $password);
  57.  
  58. $sql = <<<SQL
  59. SELECT *
  60. FROM `users`
  61. WHERE `username`='$username'
  62. SQL;
  63.  
  64. $result = $db->query($sql);
  65. $count->num_rows;
  66.  
  67. if($count==1){
  68. while ($row = mysqli_fetch_array($result)) {
  69. $hash = $row['password'];
  70. $ug = $row['user_group'];
  71. }
  72.  
  73. salt();
  74.  
  75. $options=['salt'=>$bcrypt_salt, 'cost'=>12];
  76. $password=$argv[1];
  77.  
  78. if (crypt($password,$hash) == $hash) {
  79. $_SESSION['login_user']= $username;
  80. $_SESSION['user_group']= $ug;
  81. header("location:index.php");
  82. }
  83. else {
  84. $error = "Username or password is invalid!";
  85. }
  86. }
  87. else {
  88. $error = "That username doesn't exist!";
  89. }
  90. ob_end_flush();
  91. }
  92. }
  93.  
  94. // db connect
  95. $db = new mysqli('HOST', 'USER', 'PASS', 'DB');
  96.  
  97. if($db->connect_errno > 0){
  98. die('Unable to connect to database [' . $db->connect_error . ']');
  99. }
  100.  
  101. WHERE username='$user'
  102. AND validation='$key',
  103. user_group = 'member'
  104.  
  105. <?php
  106. error_reporting(E_ALL);
  107. ini_set('display_errors', 1);
  108.  
  109. // rest of your code
  110.  
  111. $key = $_GET['key'];
  112. $key = trim($key);
  113.  
  114. if (isset($_GET['user'])) {
  115. $user = $_GET['user'];
  116. }
  117. if (isset($_GET['key']) && (strlen($_GET['key']) == 32)){
  118. $key = $_GET['key'];
  119. }
  120.  
  121. if (isset($_GET['user'])) {
  122. $user = $_GET['user'];
  123. }
  124. else{
  125. echo "User is not set";
  126. exit; // Stop the entire process, it's not set
  127. }
  128.  
  129. if (isset($_GET['key']) && (strlen($_GET['key']) == 32)){
  130. $key = $_GET['key'];
  131. }
  132. else{
  133. echo "Key is not set";
  134. exit; // Stop the entire process, it's not set
  135. }
  136.  
  137. <?php
  138. $DB_HOST = 'xxx'; // Change those
  139. $DB_USER = 'xxx'; // to your
  140. $DB_PASS = 'xxx'; // own
  141. $DB_NAME = 'xxx'; // credentials
  142.  
  143. $db = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  144. if($db->connect_errno > 0) {
  145. die('Connection failed [' . $db->connect_error . ']');
  146. }
  147.  
  148. $activation = md5(uniqid(rand(), true));
  149.  
  150. echo $activation . "<br>";
  151.  
  152. $user = "test";
  153. $key = "b5bad6f02c247458e3d888f94b568819 ";
  154. // deliberate space added at the end of the string, remove it from this when testing.
  155.  
  156. $key = trim($key); // trims off the space at the end of the key string.
  157.  
  158. echo strlen($key); // yep, gotten 32
  159.  
  160. $sql = <<<SQL
  161. UPDATE users
  162. SET validation = NULL
  163. WHERE username='$user'
  164. AND validation='$key'
  165.  
  166. SQL;
  167.  
  168. $result = $db->query($sql);
  169.  
  170. if($result) {
  171. echo "Success" . "<br>";
  172. // This does not always mean it was truly successful. Use affected_rows()
  173. }
  174.  
  175. else{
  176. echo "Failed" . mysqli_error($db);
  177. }
  178.  
  179. $affected = $db->affected_rows;
  180.  
  181. if($affected){
  182. echo "Affected yes";
  183. }
  184.  
  185. else{
  186. echo "Not affected";
  187. }
Add Comment
Please, Sign In to add comment