0
  1. It contains at least one lowercase letter.
  2. It contains at least one digit, which can be in any position except the first and last position.
  3. It contains at least one special character (non-alphanumeric: i.e. symbols), which can be in any position except the first and last position.
  4. It does not contain sequences of two or more characters from the User ID.
  5. It is not a reverse of the user ID nor contain a reverse of the user ID.
  6. It does not contain sequences of three or more characters from the previous chosen or given password.
  7. It does not contain a sequence of two or more characters more than once within the password (e.g., a39tzb39r).
  8. It does not contain a sequence of three or more repeating or sequential numbers or characters in a row (e.g., ax222rm, ct15mnoRx).

Please let me know the command to test these individually.

closed as unclear what you're asking by Kusalananda, Jeff Schaller, dhag, G-Man, GAD3R Dec 21 '18 at 22:09

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Hi! Do you need to generate passwords respecting these rules, or validate that an existing string is conformant? – dhag Dec 21 '18 at 18:56
  • 3
    This was the stupidest thing I've read today. Sorry. It disqualifies perfectly good passphrases and promotes hard to remember (and therefore short) passwords. Tip: test each condition individually. – Kusalananda Dec 21 '18 at 18:58
  • 4
    If you do then your users will write their passwords on post-it notes, and stick them to their monitor xkcd.com/936 Teach them how to create good passwords. – ctrl-alt-delor Dec 21 '18 at 20:16
  • 4
    The only way to implement rule 6, is to store clear text passwords. This is a big NO: supper bad practice, and probably in violation of gdpr en.wikipedia.org/wiki/General_Data_Protection_Regulation If a user re-uses a password, they will (especially if they are hard to remember). Then if your site gets hacked, then you will leak there password, and it can be used on the other sites. – ctrl-alt-delor Dec 21 '18 at 20:23
  • 2
    This question is very clear, it is just a bad idea (Why the votes to close?). – ctrl-alt-delor Dec 21 '18 at 20:26
1

Do it with regex

1- It contains at least one lowercase letter.

[a-z]

2- It contains at least one number, which can be in any position except the first and last position.

.[0-9].

3- It contains at least one special character ID, which can be in any position except the first and last position.

.[^a-z0-9A-Z].

4- It does not contain sequences of two or more characters from the User ID.

For each 2 char of the id (but I think you mean username (vs full name) as id's are numarical) ((?!$U).)

5- It is not a reverse of the user ID nor contain a reverse of the user ID.

U=&(whoami | tac) ((?!$U).)

6- It does not contain sequences of three or more characters from the previous chosen or given password.

same as #4

7- It does not contain a sequence of two or more characters more than once within the password (e.g., a39tzb39r). 8- It does not contain a sequence of three or more repeating or sequential numbers or characters in a row (e.g., ax222rm, ct15mnoRx).

(.{2,})\1

Then put it all together;

echo -n $PASS | grep -P '[a-z]' | grep -P '.[0-9].' | grep -P '.[^a-z0-9A-Z].' | grep -vP "((?!$U).)|$ETC"

Expanding the $Us are for loops you should be able to figure out... but as the comments mention the only proper test for secure password is that it is longer than 14 characters (And salted, and preferably restricted the keys for things like SSH )

  • 2
    Note that . matches any character. So, in step 2, for example, your regular expression would match 000 which has a digit in both first and last position. Also quote $PASS. – Kusalananda Dec 21 '18 at 20:27
  • Please let me know which regex command should be used to verify. – user328010 Dec 21 '18 at 20:42
  • 3
    @user328010 Seriously, did you even read the answer? – Kusalananda Dec 21 '18 at 20:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.