Mecano Posted July 24, 2015 Posted July 24, 2015 (edited) Hallo members,Looking for the right regex for password validation, the password must be eight characters long including at least 1 number and includes both lower and uppercase letters and at least 1 special character.€ , £ and letters with umlauts, accents, etc. are not allowed.I have made a test gui with two different validations, this is just for testing purposes, but is this right way to do it?'((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})'and'([A-Za-z: ]+\$([A-Z0-9]+)([\s]*[A-Za-z: ]+\$([A-Z0-9]+)){0,2})' The test GUIexpandcollapse popup#NoTrayIcon #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Local $GUI, $Password, $Button1, $Button2 $GUI = GUICreate("Form1", 412, 261, 192, 124) $Password = GUICtrlCreateInput("", 96, 32, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD)) GUICtrlSendMsg(-1, $EM_SETCUEBANNER, False, "8 characters") GUICtrlSetLimit(-1, 8, 8) $Button1 = GUICtrlCreateButton("Export", 97, 77, 193, 25) $Button2 = GUICtrlCreateButton("Import", 97, 123, 193, 25) GUISetState(@SW_SHOW) While 1 Local $StringPassw = GUICtrlRead($Password) Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; Export If $StringPassw = "" Then MsgBox(16, "Error!", "Password can not be empty") GUICtrlSetState($Password, $GUI_FOCUS) ; regex for testing, the password must be eight characters including one uppercase letter, one special character and alphanumeric characters. ElseIf StringRegExp($StringPassw, '((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})') Then MsgBox(0, "Strong", "Password is 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") ; Debug ; Export() GUICtrlSetState($Button1, $GUI_DISABLE) Else MsgBox(64, "Password is not strong!", "Re-type password, Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") GUICtrlSetData($Password, "") EndIf Case $Button2 ; Import If $StringPassw = "" Then MsgBox(16, "Error!", "Password can not be empty") ; another regex for testing GUICtrlSetState($Password, $GUI_FOCUS) ElseIf StringRegExp($StringPassw, '([A-Za-z: ]+\$([A-Z0-9]+)([\s]*[A-Za-z: ]+\$([A-Z0-9]+)){0,2})') Then MsgBox(0, "Strong", "Password is 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") ; Debug ; Import() GUICtrlSetState($Button2, $GUI_DISABLE) Else MsgBox(64, "Password is not strong!", "Re-type password, Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters") GUICtrlSetData($Password, "") EndIf EndSwitch WEnd searched the forum, but good not find a good exampleEdit;the password must be eight characters long including at least 1 number and includes both lower and uppercase letters and at least 1 special character.€ , £ and letters with umlauts, accents, etc. are not allowed. I need only a single regular expressionThanks in advance Edited July 24, 2015 by Mecano
ViciousXUSMC Posted July 24, 2015 Posted July 24, 2015 This might help you: And Just recently I needed something similar and the code in this thread was very easy to use and worked perfectly:
Mecano Posted July 24, 2015 Author Posted July 24, 2015 ViciousXUSMC, thanks for the answer, both topics I find already and they are very useful, but I need a good pattern.Sorry I forget to tell that € , £ and letters with umlauts, accents, etc. are not allowed.(?=.*\W) this will find any non-word character
jguinch Posted July 24, 2015 Posted July 24, 2015 ?(?=^.{8}$)(?=.*[[:upper:]])(?=.*[[:alnum:]])(?=.*[^[:alnum:]])(?!.*[^[:ascii:]]) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Mecano Posted July 24, 2015 Author Posted July 24, 2015 jguinch,thanks, your code works,but let say aABbgh@q is now valid tooMy first question is wrong, sorryThe good question must be:at least 1 number and includes both lower and uppercase letters and at least 1 special character
jguinch Posted July 24, 2015 Posted July 24, 2015 well,(?=^.{8}$)(?=.*\d)(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:alnum:]])(?=.*[^[:alnum:]])(?!.*[^[:ascii:]]) Mecano 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Mecano Posted July 24, 2015 Author Posted July 24, 2015 jguinch, That's the pattern I need, thank youSolved
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now