Jump to content

How to check, that a string contains capital letters or a number or a special letter?


Go to solution Solved by Nine,

Recommended Posts

I am writing a program that checks, that a string is okay for a password.

I need to chechk that the string contains at least a number a capital letter and a special charachter?

Here is my example code:

$Input = InputBox(64,"Type password","")
If GUICtrlRead($Input) == "" Or $Input .... CHECK Then
    MsgBox(0,"password","password not okay")
Else
    MsgBox(0,"okay","password okay")
EndIf

 

Link to comment
Share on other sites

  • Solution

Maybe this ?

$Input = InputBox("Title","Type password","")
If @error Then Exit
If StringRegExp($Input, "[A-Z]") And StringRegExp($Input, "[0-9]") And StringRegExp($Input,"[!/$%?&*+=]") Then
    MsgBox(0,"password","password is OK")
Else
    MsgBox(0,"okay","password not okay")
EndIf

Or even this better :

$Input = InputBox("Title","Type password","")
If @error Then Exit
If StringRegExp($Input, "(?=.*[A-Z])(?=.*[0-9])(?=.*[!/$%?&*+=])") Then
    MsgBox(0,"password","password is OK")
Else
    MsgBox(0,"okay","password not okay")
EndIf

 

Edited by Nine
Link to comment
Share on other sites

8 hours ago, DannyJ said:

I need to chechk that the string contains at least a number a capital letter and a special charachter?

So a password could contain just UPPERCASE letters, a number and a special char?

Code hard, but don’t hard code...

Link to comment
Share on other sites

Per the requirements listed, yes.  As a good security practice, a minimum length is also advised; for example, 8 characters.

*built from @Nine's example

$Input = InputBox("Title","Type password","")
If @error Then Exit
If StringRegExp($Input, "(?=^.{8,}$)(?=.*[A-Z])(?=.*[0-9])(?=.*[[:punct:]])") Then
    MsgBox(0,"password","password is OK")
Else
    MsgBox(0,"okay","password not okay")
EndIf

 

Link to comment
Share on other sites

FYI you can also use the Unicode Character Properties supported by the regex engine. See help.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

4 hours ago, spudw2k said:

Per the requirements listed, yes.

Interesting.  

Yet an ALL-CAPS password can be guessed by brute force just as quickly as an all-lower case password.

And since I doubt that the omission of the requirement of mixed case is at the request of the user community, perhaps it’s just an oversight…


 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...