LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-12-2010, 08:22 AM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
bash script to test string complexity (like password complexity)


Hi guys, I'm looking for a script which is testing how complex an "added" string is, for example like the user is changing his password and check how complex it is, if it included letters (lower/upper case), numbers and other characters.

Im doing this for password check, the user type's the password and must be 6 characters long, have upper case letters lets say and numbers and so on.

If anyone knows where I could find some bash script which is doing this, it would be really cool.

Thanks!
 
Old 05-12-2010, 09:37 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Here's proof of concept
Code:
#!/bin/bash

readonly re_digit='[[:digit:]]'
readonly re_lower='[[:lower:]]'
readonly re_punct='[[:punct:]]'
readonly re_space='[[:space:]]'
readonly re_upper='[[:upper:]]'

score=0
for re in "$re_digit" "$re_lower" "$re_punct" "$re_space" "$re_upper"
do
    [[ $1 =~ $re ]] && let score++
done

echo "Score is $score"
Note: character class "[:punct:]" includes all the printable ASCII characters not included in the others -- ~ ! @ # $ % ^ & * ( ) _ + ` - = { } | [ ] \ : " ; < > ? , . /
 
Old 05-12-2010, 02:58 PM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
This is quite cool... thx!
 
  


Reply



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
password complexity with pam_passwdqc.so VMSlives Linux - Security 4 03-30-2009 03:19 PM
Password Complexity Rules zok Linux - Security 1 04-17-2007 04:34 PM
password complexity pasupuleti Linux - Security 18 09-24-2006 01:07 PM
password complexity moinpasha Linux - Security 11 09-13-2006 10:53 PM
password complexity moinpasha Programming 1 09-12-2006 05:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:32 AM.

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