Last active
September 19, 2019 13:23
-
-
Save MahbbRah/0a729e929ca020774c94014af5b4cfb8 to your computer and use it in GitHub Desktop.
Check if password includes user name or part of it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkPasswordForUserName(userFullName, userPass) { | |
const userNamesList = userFullName.toLowerCase().split(" "); | |
const firstThreeChars = userFullName.substring(0, 3); | |
const lowerCasePassword = userPass.toLowerCase(); | |
const isUserNameInPassword = (name) => ( | |
lowerCasePassword.includes(name) || | |
lowerCasePassword.includes(firstThreeChars) | |
); | |
return userNamesList.some(isUserNameInPassword); | |
} | |
//usage;; this will return true that means the password includes name of user! | |
checkPasswordForUserName("Mahbub Rahman", "mahbub343345"); |
Hey @MahbbRah, great gist, thanks for sharing!
How about we ignore the letter case for a more precise validation?
Also, I've made some changes on the code following functional programming standards, what do you think?function checkPasswordForUserName(userFullName, userPass) { const userNamesList = userFullName.toLowerCase().split(" "); const firstThreeChars = userFullName.substring(0, 3); const lowerCasePassword = userPass.toLowerCase(); const isUserNameInPassword = (name) => ( lowerCasePassword.includes(name) || lowerCasePassword.includes(firstThreeChars) ); return userNamesList.some(isUserNameInPassword); }
This one super cool!, Thanks for the improvement!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @MahbbRah, great gist, thanks for sharing!
How about we ignore the letter case for a more precise validation?
Also, I've made some changes on the code following functional programming standards, what do you think?