Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking Password Format
Message
From
02/06/2014 02:44:55
 
 
To
29/05/2014 16:14:15
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01600934
Message ID:
01601093
Views:
58
>All,
>
>I would like have my users to create their passwords in the following format:
>
>
>
>How do I check to see if their passwords meet the criteria once they create and/or change their passwords?
>
>•be at least 10 characters
>•contain at least 2 special characters: ! @ # $ % ^ & * _ - + = ' : ; . ,
>•contain at least 2 numbers
>•contain at least 2 uppercase and 2 lowercase letters
>•not be an old password


You can use a regex with a couple of positive lookaheads
*_______________________________________________________________________________
function PasswordTest()

	local obj
	obj = createobject('VBScript.RegExp')
	obj.IgnoreCase = .f.
	obj.Global = .f.
	local specialChars, p1, p2, p3, p4, p5
	
	specialChars = "!@#$%^&*_+=':;.,-" && hyphen at the end
	
	&& positive lookaheads = p1, p2, p3, p4
	&& length test = p5
	p1 = "(?=.*[~~].*[~~])" && at least two of those chars
	p1 = strtran(p1, '~~', specialChars )
	
	p2 = '(?=.*\d.*\d)'  && at least two digits
	p3 = '(?=.*[A-Z].*[A-Z])' && at least two uppercase
	p4 = '(?=.*[a-z].*[a-z])' && at least two lowercase
	p5 = '[\S]{10,}'	&& at least 10 non white space char
	&& p5 = '.{10,}'	&& at least 10 chars
	
	
	
	local pattern
	pattern = '^' + p1 + p2 + p3 + p4 + p5 + '$'
	
	
	obj.Pattern = pattern
	
	
	local goodOnes
	text to goodOnes noshow flags 1 pretext 7
		A1B+2;abcd
		12xxA1B+2;
	endtext
	
	
	local badOnes
	text to badOnes noshow flags 1 pretext 7
		A1B+2;abc
		A1c+2;abcd
		A1B+24abcd
	endtext
	
	
	do case
	case !PasswordResultTest(obj, goodOnes , .t.)
		? 'fail'
	
	case !PasswordResultTest(obj, badOnes , .f.)
		? 'fail'
	
	otherwise 
		? 'ok'
	endcase
	
	
endfunc
*_______________________________________________________________________________
function PasswordResultTest( regexObj, cases, expect)

	local aa[1], naa, i, pw, result, success
	
	naa =alines(aa, m.cases, 1)
	
	for i = 1 to naa
		pw = aa[m.i]
		result = regexObj.Test(pw)
		
		? 'expect ', m.expect, ' got', result, ' :', pw
		
		success = result == expect
		if( !m.success )
			return .f.
		endif
	endfor

endfunc
*_______________________________________________________________________________
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform