Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <?php
  2. require 'core.inc.php';
  3. require 'connect.inc.php';
  4. if (isset($_POST['username']) and isset($_POST['password'])) {
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7. $pass = password_hash($password, PASSWORD_DEFAULT);
  8. if (!empty($username) and !empty($pass)) {
  9. $query = "SELECT `id` FROM `users` WHERE username='".mysql_real_escape_string($username)."' and password='".$pass."'";
  10. if ($result = mysql_query($query)) {
  11. $numrows = mysql_num_rows($result);
  12. if ($numrows == 0) {
  13. echo 'Failed';
  14. } else {
  15. $user_id = mysql_result($result, 0, 'id');
  16. $_SESSION['user_id']=$user_id;
  17. header('Location: index.php');
  18. }
  19. }
  20. } else {
  21. echo 'Enter All Fields';
  22. }
  23. }
  24. ?>
  25.  
  26. <?php
  27. require 'core.inc.php';
  28. require 'connect.inc.php';
  29.  
  30. if(!loggedin()) {
  31. if(isset($_POST['firstname'],$_POST['username'],$_POST['password'],$_POST['password_again'])) {
  32. $firstname = $_POST['firstname'];
  33. $username = $_POST['username'];
  34. $password = $_POST['password'];
  35. $password_again = $_POST['password_again'];
  36. $password_hash = md5($password);
  37. if(!empty($username) and !empty($password) and !empty($password_again) and !empty($firstname)) {
  38. if ($password!=$password_again) {
  39. echo 'Passwords do not match.';
  40. } else {
  41. $query = "SELECT `username` FROM `users` WHERE `username`='$username'";
  42. $query_run = mysql_query($query);
  43. $numrows = mysql_num_rows($query_run);
  44. if($numrows == 1) {
  45. $message = "The Username ".$username." Already Exists.";
  46. echo "<script type='text/javascript'>alert('$message');</script>";
  47. } else {
  48. $query = "INSERT INTO `users` VALUES ('','".mysql_real_escape_string($username)."','".password_hash($password, PASSWORD_DEFAULT)."','".mysql_real_escape_string($firstname)."','0')";
  49. if($query_run = mysql_query($query)) {
  50. header('Location: index.php');
  51. } else {
  52. die(mysql_error());
  53. }
  54. }
  55. }
  56. } else {
  57. echo 'All Fields are Required.';
  58. }
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement