Display Password Change Requirements To Users

In this guide I will show you how to display the password requirements you have setup for your system to users when they are changing their password. The reason this is necessary is because usually they will not have any idea what the password requirements actually are. What we are going to do is add an extra function and alias in the default bash profile.

Display Password Change Requirements To Users

NOTE: This will not effect current users however there is an easy way to make it take effect for them as-well (later on in this post).

Listing The Password Requirements

We are going to be listing the password requirements in a seperate file, this is due to policies changing and it makes it much easier to update vs having the text hard coded in to user profiles.

sudo echo "### Password Requirements
# Must be at-least 7 characters long.
# Must contain 1 letter and 1 number.
# Must contain at-least 1 special character.
" > /etc/userpasswdreq && sudo chmod +r /etc/userpasswdreq

Creating The Password Requirements Function

The following function will displa the contents of our password requirements text file and then launch the actual password change utility.

passreq() {
cat /etc/userpasswdreq;

To quickly and easily add it to the default profile, you can run the following one liner (copy and paste the whole thing into the terminal).

sudo echo "passreq() { 
cat /etc/userpasswdreq;
}" >> /etc/profile

Creating The Password Change Alias

The next thing we are going to do is basically hijack anytime the user runs “passwd” without specifying a path to the utility. What we will do is run the function above instead which runs the actual utility after displaying the requirements. This alias will also be added to the default profile.

alias passwd="passreq"

Again we can quickly add this by running the following command.

sudo echo 'alias passwd="passreq"' >> /etc/profile

Setting Up For Existing Users

While the above solution works for any new users, existing users already have their bash profiles setup. So to apply this to existing users we will need to use the same method but a different target file. The following commands will do the same as the above but for all existing users.

sudo echo "passreq() { 
cat /etc/userpasswdreq;
}" >> /home/*/.bashrc

And to setup the alias we will run the next command.

sudo echo 'alias passwd="passreq"' >> /home/*/.bashrc

Thats all, now when your users attempt to change their password, they will actually see what the password requirements are. Please don’t forget to like, comment, or share. Thank you!

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud