// Based on https://phppot.com/jquery/jquery-password-strength-checker/ function checkPasswordStrength() { const number = /([0-9])/; const alphabets = /([a-zA-Z])/; const special_characters = /([~,!,@,#,$,%,^,&,*,-,_,+,=,?,>,<])/; const password = $('#password').val().trim(); const $status = $('#password-strength-status'); if (password.length < 8) { $status.removeClass(); $status.addClass('weak-password'); $status.html("Weak (should be at least 8 characters.)"); } else { if (password.match(number) && password.match(alphabets) && password.match(special_characters)) { $status.removeClass(); $status.addClass('strong-password'); $status.html("Strong password"); } else { $status.removeClass(); $status.addClass('medium-password'); $status.html("Medium (should include alphabets, numbers and special characters.)"); } } } function hasPassword() { const url = 'https://engineering.purdue.edu/GradMatch/API/student/has_password'; var check_password = false; email = $('#student_login #email').val() if (email) { email = email.trim(); $.getJSON(url, {'email':email}, function( data ) { if ( ! data['has_password'] ) { check_password = true; } }); } else { // If the user is resetting their password, we want a way to know that // so we can check the strength of the new one. The presence of a reset_password // hidden field is our clue. check_password = $('#reset_password').length ? true : false; } if ( check_password ) { // Prevent accidental duplication of status messages $('#password-strength-status').remove(); // Add the status message div $('#password').after( '
' ); // Add a keyup listener to the password field $('#password').on('keyup', checkPasswordStrength); } else { $('#password-strength-status').remove(); } } (function( $ ) { $('#student_login #email, #reset-password #password').on('change', function() { hasPassword(); }) // Call hasPassword once to add the status message div hasPassword(); })( jQuery );