Guest User

Untitled

a guest
Jun 5th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <?php
  2.  
  3. include ('includes/config.php');
  4.  
  5. $user_ip = $_SERVER['REMOTE_ADDR'];
  6. $username = isset($_POST['username']) ? trim($_POST['username']) : '';
  7. $password = isset($_POST['password']) ? trim($_POST['password']) : '';
  8. $password2 = isset($_POST['password2']) ? trim($_POST['password2']) : '';
  9. $errors = array();
  10. $success = false;
  11.  
  12. // Process the POST data.
  13. if(isset($_POST) && !empty($_POST)){
  14. // Validate user name.
  15. if(empty($username)){
  16. $errors[] = 'Please provide a user name.';
  17. }else if(strlen($username) < 3 || strlen($username) > 16){
  18. $errors[] = 'User name must be between 3 and 16 characters in length.';
  19. }else if(ctype_alnum($username) === false){
  20. $errors[] = 'User name must consist of numbers and letters only.';
  21. }else{
  22.  
  23. // Check if username already exists in the database.
  24. $sql = "SELECT szUserID FROM TGLOBAL_GSP.dbo.TACCOUNT WHERE szUserID = ?";
  25. $stmt = odbc_prepare($connection,$sql);
  26. $args = array($username);
  27. if(!odbc_execute($stmt,$args)){
  28. $errors[] = 'Failed to determine if this username already exists in the database.';
  29. }elseif($row = odbc_fetch_array($stmt)){
  30. $errors[] = 'User name already exists, please choose a different user name.';
  31. }
  32. }
  33.  
  34. // Validate user password.
  35. if(empty($password)){
  36. $errors[] = 'Please make password.';
  37. }else if(strlen($password) > 16){
  38. $errors[] = 'Password is too long.';
  39. }else if($password != $password2){
  40. $errors[] = 'Password must be same.';
  41. }
  42.  
  43.  
  44. if(empty($errors[0])){
  45. $password = md5($password); // šifrování hesla
  46. $result = odbc_exec($connection, "SELECT * FROM TGLOBAL_GSP.dbo.TACCOUNT"); // vyčtení záznamů
  47. $row = odbc_num_rows($result); // zjištění počtu řádek
  48. $ml = $row + 1;
  49.  
  50. $sql = "INSERT INTO TGLOBAL_GSP.dbo.TACCOUNT (dwUserID, szUserID,szPasswd,bCheck) VALUES ($ml, '$username', '$password', 1)";
  51.  
  52. odbc_exec($connection,$sql);
  53.  
  54. echo "<script type='text/javascript'>alert('Account ". $username ." Succesfully Created')</script>";
  55.  
  56. }else echo "<script type='text/javascript'>alert('". $errors[0] ."')</script>";
  57. if(!empty($errors[0])){$_SESSION['reg_error'] = $errors['0'];}
  58. echo'<meta http-equiv="refresh" content="5; URL=./index.php">';
  59. //header("Location: http://www.v4story.eu");
  60. }
  61. ?>
Add Comment
Please, Sign In to add comment