mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
51 lines
1.9 KiB
JavaScript
Executable File
51 lines
1.9 KiB
JavaScript
Executable File
$(document).ready(function() {
|
|
$('#password').keyup(function() {
|
|
$('#result').html(checkStrength($('#password').val()))
|
|
})
|
|
|
|
function checkStrength(password) {
|
|
var strength = 0
|
|
var re = /^[a-z0-9\-]+$/i
|
|
var result = re.test(password)
|
|
if (result) {
|
|
$('#result').removeClass()
|
|
$('#result').addClass('short')
|
|
return 'Use alphanumeric characters for stronger passwords'
|
|
}
|
|
|
|
if (password.length < 6) {
|
|
$('#result').removeClass()
|
|
$('#result').addClass('short')
|
|
return 'Too short'
|
|
}
|
|
if (password.length > 7)
|
|
strength += 1
|
|
// If password contains both lower and uppercase characters, increase strength value.
|
|
if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))
|
|
strength += 1
|
|
// If it has numbers and characters, increase strength value.
|
|
if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))
|
|
strength += 1
|
|
// If it has one special character, increase strength value.
|
|
if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))
|
|
strength += 1
|
|
// If it has two special characters, increase strength value.
|
|
if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/))
|
|
strength += 1
|
|
// Calculated strength value, we can return messages
|
|
// If value is less than 2
|
|
if (strength < 2) {
|
|
$('#result').removeClass()
|
|
$('#result').addClass('weak')
|
|
return 'Weak'
|
|
} else if (strength == 2) {
|
|
$('#result').removeClass()
|
|
$('#result').addClass('good')
|
|
return 'Good'
|
|
} else {
|
|
$('#result').removeClass()
|
|
$('#result').addClass('strong')
|
|
return 'Strong'
|
|
}
|
|
}
|
|
}); |