LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-20-2017, 10:54 AM   #1
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Rep: Reputation: Disabled
password validation with regex


Conditions:

1. The password must have between six and thirteen word characters \w
2. It must include at least one lowercase character [a-z]
3. It must include at least three uppercase characters [A-Z]
4. It must include at least one digit \d

I tried this command:
Code:
^(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z]{3,})\w{6,13}$
and this is working partially, but only if uppercase chars repeated...

Match:
PASSWORD32pa3
passwrd32ABNA
password34AAA
passord345AAA
passw2ordAAAA

Not match:
passwo3ABsSA
PAeQsaaa23

Why does not match "passwo3ABsSA"?

I tested it with regextester.
 
Old 09-20-2017, 12:22 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,317
Blog Entries: 13

Rep: Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372
It is matching 3 uppercase letters in a group, or in sequence. In that test case, it happens to be the one test case where you do not have 3 or more uppercase letters in sequence.

Try:
Code:
(?=(.*?[A-Z]){3})
 
1 members found this post helpful.
Old 09-20-2017, 12:31 PM   #3
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thanks.
 
Old 09-20-2017, 08:00 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,148
Blog Entries: 4

Rep: Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232Reputation: 3232
Personally, I think that such policies are misguided, for three reasons:
  • If the user didn't tape his password on the underside of the keyboard, look underneath his coffee cup.
  • A vast number of possibilities are excluded from consideration.
  • At the end of the day, every human password is "pronounceable."

The only way to strengthen login is to abandon the use of "pure passwords" and to adopt two-factor authentication. Give everyone a random-number fob and require them to type in the number that they presently see displayed upon their fob. Or, give them a plastic card that they must swipe while entering a PIN.

Last edited by sundialsvcs; 09-20-2017 at 08:02 PM.
 
1 members found this post helpful.
Old 09-22-2017, 03:29 AM   #5
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Okay. I am beginner, just learning regex. I would like to find solutions simple password validation with regular expression only.
(Also I am searching on-line lessons for regex.)

But anyway thank you for your advice.
 
Old 09-22-2017, 04:40 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,500

Rep: Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535Reputation: 5535
hard to specify such things using regexp: at least three uppercase characters - but not consecutive
Code:
(?=(.*[A-Z]){3,})
will work better
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to set password validation for CONMAN connection ? rajes4india Linux - Software 1 10-11-2014 12:18 PM
Password length validation Agustina Linux - Software 2 07-17-2012 05:09 PM
[SOLVED] Bash / grep regex validation for path names jomann Programming 3 02-01-2012 08:47 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Confused trying to do password validation in PHP Pcghost Programming 4 02-02-2004 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration