Page 1 of 1 1
Topic Options
#124420 - 2004-08-04 04:13 PM Verify Password Complexity
GSUK Offline
Starting to like KiXtart

Registered: 2004-03-10
Posts: 125
Hi there,

I have written a script that creates a new user account in AD and sets the password that you input. The problem is the AD password policy requires the password to be a minimum of 7 characters and have at least one number and one lower and upper case letter in it. It’s easy enough to check the length of the string but how do I check it for upper and lower cases and numbers?

Here’s what I’ve managed so far…


Code:
 
Function cmdVerifyPassword_Click()

If $txtPassword.Text = ""
$= $Form.MsgBox("The password cannot be empty.", "User password change", 1)
Else
If Len($txtPassword.Text) < 7
$= $Form.MsgBox("The password cannot be less than 7 characters long.", "User password change", 1)
Else
If
; Here's the bit thats missing!
;...
Else
$adsUser.SetPassword($txtPassword.Text)
$= $Form.MsgBox("The password is vallid!")
EndIf
EndIf
EndIf

$txtPassword.Text = ""
$adsUser = Nothing

EndFunction




PS. Using Kixforms.
Thanks in advance,
Glenn


Top
#124421 - 2004-08-04 04:20 PM Re: Verify Password Complexity
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
hint
use == for case sensitive compares or use the ASC() function to check the range.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124422 - 2004-08-04 04:27 PM Re: Verify Password Complexity
GSUK Offline
Starting to like KiXtart

Registered: 2004-03-10
Posts: 125
I thought about reading the acsii codes but I was hoping there may have been a simpler solution...
Top
#124423 - 2004-08-04 04:36 PM Re: Verify Password Complexity
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The simpler solution may be to generate a password that meets the requirement in the first place!

http://www.kixforms.org/forum/viewtopic.php?t=43
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124424 - 2004-08-04 04:37 PM Re: Verify Password Complexity
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
what about something like this, i haven't tested it

Code:

if len($pwd) < 7
? "invalid"
else
if ucase($pwd) == $pwd or lcase($pwd) == $pwd
? "invalid"
else
$nums = 0
for $j = 0 to 9
if instr($pwd,$j)
$nums = $nums+1
endif
next
if $nums = 0
? "invalid"
endif
endif
endif

_________________________
Eric

Top
#124425 - 2004-08-04 04:43 PM Re: Verify Password Complexity
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
maciep,

close but no cigar:

Code:
    if ucase($pwd) = $pwd or lcase($pwd) = $pwd
? "invalid"
endif



will evaluate true in any case ...

Haven't tested the numeric part but that should work !
_________________________



Top
#124426 - 2004-08-04 04:43 PM Re: Verify Password Complexity
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Create yourself a library of simple type checks, something like this:
Code:
 
Function IsPunct($sCharacter)
$IsPunct=InStr("!,.?':;-"+'"',$sCharacter)
Exit 0
EndFunction

Function IsXDigit($sCharacter)
$IsXDigit=InStr("1234567890ABCDEF",$sCharacter)
Exit 0
EndFunction

Function IsDigit($sCharacter)
$IsDigit=InStr("1234567890",$sCharacter)
Exit 0
EndFunction

Function IsLower($sCharacter)
Dim $OldSetting
$OldSetting=SetOption("CaseSensitivity","ON")
$IsLower=InStr("abcdefghijklmnopqrstuvwxyz",$sCharacter)
$OldSetting=SetOption("CaseSensitivity",$OldSetting)
Exit 0
EndFunction

Function IsUpper($sCharacter)
Dim $OldSetting
$OldSetting=SetOption("CaseSensitivity","ON")
$IsUpper=InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",$sCharacter)
$OldSetting=SetOption("CaseSensitivity",$OldSetting)
Exit 0
EndFunction

Function IsAlpha($sCharacter)
$IsAlpha=IsUpper($sCharacter) | IsLower($sCharacter)
Exit 0
EndFunction



Now you can check the types simply by saying:
Code:
$c="A"
If IsUpper($c) $c " is upper case" EndIf

$c="8"
If IsDigit($c) or IsDigit($c) $c " is either a letter or a number" EndIf



Top
#124427 - 2004-08-04 04:53 PM Re: Verify Password Complexity
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
oops, i was used to case sensitivity being on from the golf tournament. updated my code, it should work now
_________________________
Eric

Top
#124428 - 2004-08-04 05:06 PM Re: Verify Password Complexity
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
My brain hurts but this seems to work ... very kludgy though, I like Richards sample with the library of functions much more !

Code:


forget this ... I misunderstood the rules :)
maciep's code is now working perfectly, still like Richard's approach more ;)



Edited by Jochen (2004-08-04 05:10 PM)
_________________________



Top
#124429 - 2004-08-04 05:19 PM Re: Verify Password Complexity
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
That's weird - I posted a sample and it's disappeared!

Anyhoo, using the Is* functions described above, here is one way of checking that a password contains at lease one digit, at least one lower case letter and at least one upper case letter:

Code:
While 1
"Enter password: "
GetS $s
if $s="q" Exit 0 EndIf
If IsPasswordOk($s)
"Password is OK" ?
Else
"Password fails test" ?
EndIf
Loop

Function IsPasswordOK($s)
Dim $iHasDigit, $iHasLower, $iHasUpper

$IsPasswordOK=0
While $s
$iHasDigit=$iHasDigit | IsDigit(Left($s,1))
$iHasLower=$iHasLower | IsLower(Left($s,1))
$iHasUpper=$iHasUpper | IsUpper(Left($s,1))
$s=SubStr($s,2)
Loop
If $iHasDigit AND $iHasLower AND $iHasUpper $IsPasswordOK=1 EndIf
Exit Not $IsPasswordOK
EndFunction


Top
#124430 - 2004-08-05 07:03 PM Re: Verify Password Complexity
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Well, I guess this thread is as good as any to stop lurking in...

We're running into a similar situation at my office, except our password policy requries 3 of 4 things: uppercase, lowercase, numbers, and "special characters".

I haven't yet managed to tap into AD (much less NDS), but I do have a working complexity checker using KiXforms for a pretty front-end, although it's a bit lengthier than Richard's:

Code:
Break ON

$frmRoot = CreateObject("Kixtart.Form")
If @ERROR
$nul=SetConsole("Show")
"KiXforms.dll not installed/registered" ?
Copy @SCRIPTDIR+"\KiXforms.dll" "%WINDIR%"
If @INWIN = "1"
Shell "%COMSPEC% /c Regsvr32 /s %WINDIR%\KiXforms.dll"
Else
Shell "%COMSPEC% /c %WINDIR%\System\Regsvr32 /s %WINDIR%\KiXforms.dll"
EndIf
$frmRoot = CreateObject("Kixtart.Form")
If @ERROR
"Unable to register KiXforms.dll, please call the helpdesk." ??
"Press ENTER to continue..." ?
Get $S
Exit(1)
EndIf
EndIf

;Create KixForms Password Entry dialog
$System = CreateObject("Kixtart.System")

;KD START

;Intialize Form.
$Form1 = $System.Form()
$Form1.Text = "Password Entry"
$Form1.Height = 285

;Initialize Information Box.
$Label1 = $Form1.Controls.Label()
$Label1.Height = 145
$Label1.Left = 15
$Label1.Text = "Please enter a password for your local account. In order to meet Incredible Technologies' password complexity requirements, it must be at least seven characters long and contain three of the following:" + CHR(10) + CHR(10) + " A) Upper-case letters." + CHR(10) + " B) Lower-case letters." + CHR(10) + " C) Numbers." + CHR(10) + " D) Special characters, such as punctuation marks." + CHR(10) + CHR(10) + "Please enter a password and click 'OK' to continue."
$Label1.Top = 15
$Label1.Width = 259

;Initialize Text Box.
$TextBox1 = $Form1.Controls.TextBox()
$TextBox1.Height = 20
$TextBox1.Left = 90
$TextBox1.Text = ""
$TextBox1.Top = 175
$TextBox1.Width = 100
$TextBox1.PasswordChar = "*"

;Initialize "OK" Button.
$Button1 = $Form1.Controls.Button()
$Button1.Height = 23
$Button1.Left = 105
$Button1.Text = "OK"
$Button1.Top = 210
$Button1.Width = 75
$Button1.OnClick = "Complexity"

;KD END

$Form1.Show
While $Form1.Visible
$=Execute($Form1.DoEvents())
Loop
Exit 1

Function Complexity
;Set Variables.
$string = $TextBox1.Text
$dir = @SCRIPTDIR + "/temp.txt"
$length = Len($string)

;Check to see if password meets length requirements, return to main form if it fails.
If $length < 7
$Form1.Hide
$=$Form1.MsgBox ("Your password does not meet length requirements. Click 'OK' and try again.","Invalid Password")
$Form1.Show
Exit sub
EndIf

;Parse password to ASCII values, sending output to array.
DIM $pwarray[Len($string)]
DIM $pwcheck[Len($string)]
For $chr = 1 To Len($string)
$pwarray[$chr]=ASC(SubSTR($string,$chr,1))
If $pwarray[$chr] > 96 AND $pwarray[$chr] < 123
$pwcheck[$chr] = "Lowercase"
EndIf
If $pwarray[$chr] > 64 AND $pwarray[$chr] < 91
$pwcheck[$chr] = "Uppercase"
EndIf
If $pwarray[$chr] = 32
$pwcheck[$chr] ="Space"
EndIf
If $pwarray[$chr] > 47 AND $pwarray[$chr] < 58
$pwcheck[$chr] ="Number"
EndIf
If $pwarray[$chr] > 32 AND $pwarray[$chr] < 48
$pwcheck[$chr] ="Character"
EndIf
If $pwarray[$chr] > 90 AND $pwarray[$chr] < 97
$pwcheck[$chr] ="Character"
EndIf
If $pwarray[$chr] > 122 AND $pwarray[$chr] < 127
$pwcheck[$chr] ="Character"
EndIf
Next

;Initialize strings to check array for.
$lower = "Lowercase"
$upper = "Uppercase"
$pwarray = "Character"
$num = "Number"

;Check array for existence of types of characters.
$l = isinarray($pwcheck,$lower)
$u = isinarray($pwcheck,$upper)
$c = isinarray($pwcheck,$pwarray)
$n = isinarray($pwcheck,$num)
$test = $l + $u + $c + $n
$test2 = "" + $l + $u + $c + $n

;Generate error codes based on what's in $test2.
If $test2 = "1000"
$err = "Your password only contains lower-case letters. A valid password must also contain two of the following: At least one number, at least one upper-case letter, and at least one special character."
EndIf

If $test2 = "0100"
$err = "Your password only contains upper-case letters. A valid password must also contain two of the following: At least one number, at least one lower-case letter, and at least one special character."
EndIf

If $test2 = "0010"
$err = "Your password only contains special characters. A valid password must also contain two of the following: At least one number, at least one upper-case letter, and at least one lower-case letter."
EndIf

If $test2 = "0001"
$err = "Your password only contains numbers. A valid password must also contain two of the following: At least one special character, at least one upper-case letter, and at least one lower-case letter."
EndIf

If $test2 = "1100"
$err = "Your password must also contain at least one number or one special character."
EndIf

If $test2 = "1010"
$err = "Your password must also contain at least one upper-case letter or one number."
EndIf

If $test2 = "1001"
$err = "Your password must also contain at least one upper-case letter or one special character."
EndIf

If $test2 = "0110"
$err = "Your password must also contain at least one lower-case letter or one number."
EndIf

If $test2 = "0101"
$err = "Your password must also contain at least one lower-case letter or one special character."
EndIf

If $test2 = "0011"
$err = "Your password must also contain at least oen lower-case letter or one upper-case letter."
EndIf

;Verify that password meets complexity requirements, returning to main form if it fails.
If $test < 3
$Form1.Hide
$=$Form1.MsgBox ("The password you entered does not meet complexity requirements. $err Click 'OK' and try again.","Invalid Password")
$Form1.Show
Else
$Form1.Hide
$=$Form1.MsgBox ("The password you entered meets complexity requirements!","Password validated!")
Quit
EndFunction

Function isinarray($array,$string, optional $pos)
DIM $element, $cmd, $vars, $arraydim, $a, $rc, $posvars

$isinarray=0
$pos=Val($pos)

Select
Case VarType($array) & 8192
Select
Case UBound($array,2)=-1
If AScan($array,$string)=-1
$isinarray=0
Return
Else
If $pos
$isinarray=''
For $a=0 To UBound($array)
If $array[$a]=$string
$isinarray=$isinarray+','+$a
EndIf
Next
$isinarray=Split(SubSTR($isinarray,2),',')
If UBound($isinarray)=0
$isinarray=$isinarray[0]
EndIf
Else
$isinarray=1
EndIf
Return
EndIf
Case UBound($array,27)=-1
$arraydim=0
Do
$arraydim=$arraydim+1
Until UBound($array,$arraydim)=-1
$arraydim=$arraydim-1
$vars='$sub_a'
For $a=2 To $arraydim
$vars=$vars+', $sub_'+CHR($a+96)
Next
$cmd='dim '+$vars+@CRLF
$cmd=$cmd+'$isinarray=""'+@CRLF
For $a=1 To $arraydim
$cmd=$cmd+'for $sub_'+CHR($a+96)+'=0 to ubound($array,'+$a+')'+@CRLF
$posvars=$posvars+'+","+$sub_'+CHR($a+96)
Next
$posvars=SubSTR($posvars,6)
$cmd=$cmd+'if $array['+$vars+']=$string'+@CRLF
$cmd=$cmd+'if $pos'+@CRLF
$cmd=$cmd+'$isinarray=$isinarray+chr(13)+'+$posvars+@CRLF
$cmd=$cmd+'else'+@CRLF
$cmd=$cmd+'$isinarray=1'+@CRLF
$cmd=$cmd+'return'+@CRLF
$cmd=$cmd+'endif'+@CRLF
$cmd=$cmd+'endif'+@CRLF
For $a=1 To $arraydim
$cmd=$cmd+'next'+@CRLF
Next
$cmd=$cmd+'$isinarray=split(substr($isinarray,1),chr(13))'+@CRLF
$cmd=$cmd+'if ubound($isinarray)=0'+@CRLF
$cmd=$cmd+'$isinarray=$isinarray[0]'+@CRLF
$cmd=$cmd+'endif'+@CRLF
$rc=Execute($cmd)
Case 1
$isinarray=0
EndSelect
Case $string=''
$isinarray=0
Case $string=$array
$isinarray=1
Case 1
$isinarray=0
EndSelect
EndFunction



--Eriq.

Top
#124431 - 2004-08-05 08:20 PM Re: Verify Password Complexity
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to check shortly for cryptic enough password, this quickie code should do:
Code:
 
ComplexPass("whatEver")
function ComplexPass($password)
dim $temp,$counter,$complexity[3]
for $counter=1 to 255
$temp=join(split($password,chr($counter)),"")
if $temp<>$password
select
case $counter>47 and $counter<58 $complexity[0]=" "
case $counter>64 and $counter<91 $complexity[1]=" "
case $counter>96 and $counter<123 $complexity[2]=" "
case 1 $complexity[3]=" "
endselect
endif
next
$complexPass=len(join($complexity,""))
endfunction



hmm... not that short after all, but suites ya
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.076 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org