2

I need to make sure a person's password meets specific criteria before they can continue creating their account. I would like to add a statement checking for ', ", and ,. The application is in VBScript. This is what I have so far. I cannot find anything on the web.

IsComplex = True

'Check Length
If Len(cPassword) < 8 Then
    IsComplex = False
End If

'Check for lowercase letters
HasLowerCase = False
For x = 97 to 122
    If Instr(4,cPassword,chr(x)) > 0 Then
        HasLowerCase = True
    End If
Next
If HasLowerCase = False Then
    IsComplex = False
    cForceChange = "E"
End If

'Check for uppercase letters
HasUpperCase = False
For x = 65 to 90
    If Instr(1,cPassword,chr(x)) > 0 Then
        HasUpperCase = True
    End If
Next
If HasUpperCase = False Then
    IsComplex = False
    cForceChange = "E"
End If

'Check for numbers
HasNumber = False
For x = 48 to 57
    If Instr(1,cPassword,chr(x)) > 0 Then
        HasNumber = True
        cForceChange = "E"
    End If
Next
If HasNumber = False Then
    IsComplex = False
    cForceChange = "E"
End If
Bond
  • 16,071
  • 6
  • 30
  • 53
Benswana
  • 33
  • 6
  • Use Regex [(info)](http://www.regular-expressions.info/) [(usage)](http://stackoverflow.com/questions/6675920/using-classic-asp-for-regular-expression) - it's far more useful in this respect. – Paul Aug 03 '15 at 11:18
  • Thanks will look into this next time, would much rather just add a statement to this for now. – Benswana Aug 03 '15 at 11:55

1 Answers1

2

You can check for them literally:

If InStr(cPassword, "'")  > 0 Then  ' Single-quote found
If InStr(cPassword, """") > 0 Then  ' Double-quote found (need to use TWO quotes)
If InStr(cPassword, ",")  > 0 Then  ' Comma found

The only tricky one is the double-quote ("). Since VBScript uses this for string literals, you must escape it (by using two of them) when you need to refer to it within a string literal.

Bond
  • 16,071
  • 6
  • 30
  • 53