I'd like to create to create an user account while customized command line installation and the following code does almost pretty well:

```
#!/bin/bash
#nameofuser stands for the new account
#skel is for the a skel folder outside /etc/skel     
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " nameofuser
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null

 if [ $? -eq 0 ]; then
 echo "$username exists!"
 exit 1

else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $nameofuser -c new created user -k $skel
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi

```

I need some help with the second part and a reloop if the input is null or doesn't meet some password specs.

So this is about the second part

How could I make sure that the if statement proofs some stuff like minimum password lenth and if the password contains special chars and numbers or numbers at least?

How could I force the user to retype the password if this check does not meet the given values?