I'm creating a script that would accept user inputs in the form of a registration. Everything is all set up I just wanted to add one bit of a function here. I would like to prohibit users from using passwords that are part of their username. I would like to ask for help in formulating the script for it but here's what I have for now.
Assuming that both "username" and "password" are variables
passcheck=$(echo "*$username*")
if ($username = $passcheck)
then
echo "You can't use a password with your username in it!"
else
echo "ok"
What i'm trying to achieve here is that as long as any part of the whole username is used as a password despite having numbers or symbols AFTER or BEFORE it would be unacceptable
Example of an invalid input:
username=gifter
password=gifter100!
Another example of an invalid input:
username=doctor
password=thegooddoctor100!
Example of a valid input:
username=starbucks
password=star100bucks!
A case statement works well for this and is POSIX-compatible:
case "$password" in
*$username*) echo "You can't use a password with your username in it!" ;;
*) echo "OK" ;;
esac