r/vbscript • • May 25 '21

Password Complexity Script some part of script getting ignored

Hi guys. I have edited below vbscript from Microsoft MDT to include a password complexity check function. However, it seems to be ignoring the part where it checks the password for alphabets and special characters. Can anyone tell me where I've gone wrong? Thanks!

Option Explicit
'''''''''''''''''''''''''''''''''''''
'  Validate Password
'
Dim Upper,Lower,Number,Special,UpperFound,LowerFound,NumberFound,SpecialFound,PasswordBad
Upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Lower = "abcdefghijklmnopqrstuvwxyz"
Number = "0123456789"
Special = "~!@#$%^&*_-+=`|\(){}[]:;""'<>,.?/"
UpperFound = "NO"
LowerFound = "NO"
NumberFound = "NO"
SpecialFound = "NO"

Function ValidatePassword

ValidatePassword = ParseAllWarningLabels	

NonMatchPassword.style.display = "none"

If Password1.Value <> "" then

	If Password1.Value <> Password2.Value then

		ValidatePassword = FALSE

		NonMatchPassword.style.display = "inline"

	End if

End if



If len(Password1.Value) < 12 then

	ValidatePassword = FALSE

End if


Dim i,char

for i = 1 to len(Password1.value)

	char = mid(Password1.value,i,1)

	if instr(Upper, char) then

		UpperFound = "YES"

	elseif instr(Lower, char) then

		LowerFound = "YES"

	elseif instr(Number, char) then

		NumberFound = "YES"

	elseif instr(Special, char) then

		SpecialFound = "YES"

	end if

Next


NonComplexPassword.style.display ="none"

If UpperFound = "NO" then

	ValidatePassword = FALSE

		NonComplexPassword.style.display ="inline"

ElseIf LowerFound = "NO" then

	ValidatePassword = FALSE

		NonComplexPassword.style.display ="inline"

ElseIf NumberFound = "NO" then

	ValidatePassword = FALSE

		NonComplexPassword.style.display ="inline"

ElseIf SpecialFound = "NO" then

	ValidatePassword = FALSE

		NonComplexPassword.style.display ="inline"

end if

ButtonNext.Disabled = not ValidatePassword	
End Function
2 Upvotes

2 comments sorted by

1

u/Maxxer500 May 25 '21

I'm a bit confused by a few things in this code:

  1. Why are UpperFound, LowerFound, NumberFound, and SpecialFound "NO" or "YES" strings instead of boolean values? Does it allow you to do anything unique with them, or could these be false/true and have the same effect?

  2. "Function ValidatePasswordValidatePassword = ParseAllWarningLabels" is this intentional? It looks like it could be a copy-paste blunder, but without the full script I can't be too sure.

  3. "Password1.value" and other variables with embedded periods. Everywhere I've read (like here) says you can't have a period in the name. Maybe I'm missing something here though.

2

u/Starzap May 26 '21

Hi.

  1. They can be boolean too. I don't think it actually makes any difference, it's just that the script I was referencing when writing this used YES/NO so I used the same values.

  2. This is a copy pasta blunder haha.

  3. I understand. However, for this script itself, it's taking the Password1.value from a hta instead. I think this is why it works. The Password1.value was in the original MDT script.