Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function formhash(form, password) {
- // Create a new element input, this will be our hashed password field.
- var p = document.createElement("input");
- // Add the new element to our form.
- form.appendChild(p);
- p.name = "p";
- p.type = "hidden";
- p.value = hex_sha512(password.value);
- // Make sure the plaintext password doesn't get sent.
- password.value = "";
- // Finally submit the form.
- form.submit();
- }
- function regformhash(form, uid, email, country, age, password, conf) {
- // Check each field has a value
- if (uid.value == '' ||
- email.value == '' ||
- country.value == '' ||
- age.value == '' ||
- password.value == '' ||
- conf.value == '') {
- alert('You must provide all the requested details. Please try again');
- return false;
- }
- // Check the username
- re = /^w+$/;
- if(!re.test(form.username.value)) {
- alert("Username must contain only letters, numbers and underscores. Please try again");
- form.username.focus();
- return false;
- }
- // Check that the password is sufficiently long (min 6 chars)
- // The check is duplicated below, but this is included to give more
- // specific guidance to the user
- if (password.value.length < 6) {
- alert('Passwords must be at least 6 characters long. Please try again');
- form.password.focus();
- return false;
- }
- // At least one number, one lowercase and one uppercase letter
- // At least six characters
- var re = /(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,}/;
- if (!re.test(password.value)) {
- alert('Passwords must contain at least one number, one lowercase and one uppercase letter. Please try again');
- return false;
- }
- // Check password and confirmation are the same
- if (password.value != conf.value) {
- alert('Your password and confirmation do not match. Please try again');
- form.password.focus();
- return false;
- }
- // Create a new element input, this will be our hashed password field.
- var p = document.createElement("input");
- // Add the new element to our form.
- form.appendChild(p);
- p.name = "p";
- p.type = "hidden";
- p.value = hex_sha512(password.value);
- // Make sure the plaintext password doesn't get sent.
- password.value = "";
- conf.value = "";
- // Finally submit the form.
- form.submit();
- return true;
- }
- <?php
- include_once 'includes/register.inc.php';
- include_once 'includes/functions.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Secure Login: Registration Form</title>
- <script type="text/JavaScript" src="js/sha512.js"></script>
- <script type="text/JavaScript" src="js/forms.js"></script>
- <link rel="stylesheet" href="styles/main.css" />
- </head>
- <body>
- <!-- Registration form to be output if the POST variables are not
- set or if the registration script caused an error. -->
- <h1>Register with us</h1>
- <?php
- if (!empty($error_msg)) {
- echo $error_msg;
- }
- ?>
- <ul>
- <li>Usernames may contain only digits, upper and lowercase letters and underscores</li>
- <li>Emails must have a valid email format</li>
- <li>Passwords must be at least 6 characters long</li>
- <li>Passwords must contain
- <ul>
- <li>At least one uppercase letter (A..Z)</li>
- <li>At least one lowercase letter (a..z)</li>
- <li>At least one number (0..9)</li>
- </ul>
- </li>
- <li>Your password and confirmation must match exactly</li>
- </ul>
- <form method="post" name="registration_form" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>">
- Username: <input type='text' name='username' id='username' /><br>
- Email: <input type="text" name='email' id='email' /><br>
- Country: <input type='text' name= 'country' id='country'/><br>
- Age: <input type='number' name= 'age' id='age' min='5' max='116'/><br>
- Password: <input type="password" name="password" id="password"/><br>
- Confirm password: <input type="password" name="confirmpwd" id="confirmpwd" /><br>
- <input type="button"
- value="Register"
- onclick="return regformhash(this.form,
- this.form.username,
- this.form.email,
- this.form.country,
- this.form.age,
- this.form.password,
- this.form.confirmpwd);" />
- </form>
- <p>Return to the <a href="index.php">login page</a>.</p>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement