Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. function formhash(form, password) {
  2. // Create a new element input, this will be our hashed password field.
  3. var p = document.createElement("input");
  4.  
  5. // Add the new element to our form.
  6. form.appendChild(p);
  7. p.name = "p";
  8. p.type = "hidden";
  9. p.value = hex_sha512(password.value);
  10.  
  11. // Make sure the plaintext password doesn't get sent.
  12. password.value = "";
  13.  
  14. // Finally submit the form.
  15. form.submit();
  16. }
  17.  
  18. function regformhash(form, uid, email, country, age, password, conf) {
  19. // Check each field has a value
  20. if (uid.value == '' ||
  21. email.value == '' ||
  22. country.value == '' ||
  23. age.value == '' ||
  24. password.value == '' ||
  25. conf.value == '') {
  26.  
  27. alert('You must provide all the requested details. Please try again');
  28. return false;
  29. }
  30.  
  31. // Check the username
  32.  
  33. re = /^w+$/;
  34. if(!re.test(form.username.value)) {
  35. alert("Username must contain only letters, numbers and underscores. Please try again");
  36. form.username.focus();
  37. return false;
  38. }
  39.  
  40. // Check that the password is sufficiently long (min 6 chars)
  41. // The check is duplicated below, but this is included to give more
  42. // specific guidance to the user
  43. if (password.value.length < 6) {
  44. alert('Passwords must be at least 6 characters long. Please try again');
  45. form.password.focus();
  46. return false;
  47. }
  48.  
  49. // At least one number, one lowercase and one uppercase letter
  50. // At least six characters
  51.  
  52. var re = /(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,}/;
  53. if (!re.test(password.value)) {
  54. alert('Passwords must contain at least one number, one lowercase and one uppercase letter. Please try again');
  55. return false;
  56. }
  57.  
  58. // Check password and confirmation are the same
  59. if (password.value != conf.value) {
  60. alert('Your password and confirmation do not match. Please try again');
  61. form.password.focus();
  62. return false;
  63. }
  64.  
  65. // Create a new element input, this will be our hashed password field.
  66. var p = document.createElement("input");
  67.  
  68. // Add the new element to our form.
  69. form.appendChild(p);
  70. p.name = "p";
  71. p.type = "hidden";
  72. p.value = hex_sha512(password.value);
  73.  
  74. // Make sure the plaintext password doesn't get sent.
  75. password.value = "";
  76. conf.value = "";
  77.  
  78. // Finally submit the form.
  79. form.submit();
  80. return true;
  81. }
  82.  
  83. <?php
  84. include_once 'includes/register.inc.php';
  85. include_once 'includes/functions.php';
  86. ?>
  87. <!DOCTYPE html>
  88. <html>
  89. <head>
  90. <meta charset="UTF-8">
  91. <title>Secure Login: Registration Form</title>
  92. <script type="text/JavaScript" src="js/sha512.js"></script>
  93. <script type="text/JavaScript" src="js/forms.js"></script>
  94. <link rel="stylesheet" href="styles/main.css" />
  95. </head>
  96. <body>
  97. <!-- Registration form to be output if the POST variables are not
  98. set or if the registration script caused an error. -->
  99. <h1>Register with us</h1>
  100. <?php
  101. if (!empty($error_msg)) {
  102. echo $error_msg;
  103. }
  104. ?>
  105. <ul>
  106. <li>Usernames may contain only digits, upper and lowercase letters and underscores</li>
  107. <li>Emails must have a valid email format</li>
  108. <li>Passwords must be at least 6 characters long</li>
  109. <li>Passwords must contain
  110. <ul>
  111. <li>At least one uppercase letter (A..Z)</li>
  112. <li>At least one lowercase letter (a..z)</li>
  113. <li>At least one number (0..9)</li>
  114. </ul>
  115. </li>
  116. <li>Your password and confirmation must match exactly</li>
  117. </ul>
  118. <form method="post" name="registration_form" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>">
  119. Username: <input type='text' name='username' id='username' /><br>
  120. Email: <input type="text" name='email' id='email' /><br>
  121. Country: <input type='text' name= 'country' id='country'/><br>
  122. Age: <input type='number' name= 'age' id='age' min='5' max='116'/><br>
  123. Password: <input type="password" name="password" id="password"/><br>
  124. Confirm password: <input type="password" name="confirmpwd" id="confirmpwd" /><br>
  125. <input type="button"
  126. value="Register"
  127. onclick="return regformhash(this.form,
  128. this.form.username,
  129. this.form.email,
  130. this.form.country,
  131. this.form.age,
  132. this.form.password,
  133. this.form.confirmpwd);" />
  134. </form>
  135. <p>Return to the <a href="index.php">login page</a>.</p>
  136. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement