kudrow Posted January 15, 2015 Posted January 15, 2015 OK I am going crazy with StingRegExp. I have to be missing something. It is giving me a positive match for a SINGLE letter of the string to look for. So if I tell it to look for "pass" and the search string contains password it returns positive. Why does it not match EXACT!? I am not looking for partial matches, I need exact, case sensitive as well. Any thoughts?
JohnOne Posted January 15, 2015 Posted January 15, 2015 Code? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kudrow Posted January 15, 2015 Author Posted January 15, 2015 $inBoundip = $sClientIPAddress $inBoundData = TCPRecv ($iSocket, 5) If $inBoundData=="login" Then TCPSend ($iSocket, "success") $inBoundData = TCPRecv ($iSocket, 2048) $convert = BinaryToString ($inBoundData) $convert2 = BinaryToString (_EncDec(0, $convert)) $stringtosplit = StringSplit($convert2, "#") $username = $stringtosplit[1] $password = $stringtosplit[2] $path = "C:\accounts\" & $username & "\" & $username & ".txt" $accountExists = FileExists ($path) If $accountExists == 1 Then $datafile = FileRead ($path) $chckpass = StringRegExp($datafile, $password) The string it is evaluating is a text file containing other data including a password. I am searching the entire data file to see if $password exist in it. So if the users password is "password" and its inside the data file and $password = "pass" or "pa" or "word" or any character it returns true. It should be able to see that "pass" is not an exact match to "password".
Moderators Melba23 Posted January 15, 2015 Moderators Posted January 15, 2015 (edited) kudrow,Something like this perhaps: $sKey = "blah" Global $aString[3] = ["BlahblahBlah", " blah", "blah"] For $i = 0 To 2 If StringRegExp($aString[$i], "^" & $sKey & "$") Then ConsoleWrite("Found" & @CRLF) Else ConsoleWrite("Not Found" & @CRLF) EndIf NextM23 Edited January 15, 2015 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JohnOne Posted January 15, 2015 Posted January 15, 2015 Where's your pattern? looks like you just need StringInStr. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
mikell Posted January 15, 2015 Posted January 15, 2015 (edited) This will match the whole word only $sKey = "pa" Global $aString[3] = ["pass", " password", "pa"] For $i = 0 To 2 If StringRegExp($aString[$i], "\b" & $sKey & "\b") Then ConsoleWrite("Found" & @CRLF) Else ConsoleWrite("Not Found" & @CRLF) EndIf Next Edited January 15, 2015 by mikell
Valuater Posted January 15, 2015 Posted January 15, 2015 This is how I would do it $sKey = "pa" Global $aString[3] = ["pass", " password", "pa"] For $i = 0 To 2 If $aString[$i] == $sKey Then ConsoleWrite("Found" & @CRLF) Else ConsoleWrite("Not Found" & @CRLF) EndIf Next
jguinch Posted January 15, 2015 Posted January 15, 2015 I agree with J1 : StringInStr should suffice, no ? Also, be careful to special chars (reserved chars of RegExp) in your key that you want to search to. You should use "Q" & $sKey & "E" To match something like P@$$w0rd+ Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Valuater Posted January 15, 2015 Posted January 15, 2015 I truly believe that the == is the fastest absolute test. 8)
JohnOne Posted January 15, 2015 Posted January 15, 2015 Sure, if it's an array of words, but looks like these are data packets. and the string is in the data, somewhere. StringInStr with tell you that it's there and where it is. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kudrow Posted January 15, 2015 Author Posted January 15, 2015 (edited) Thank you for the replies everyone. I did try StingInStr before I posted for help and received the same results. I received positive returns on partial matches. I am going to evaluate the examples yall provided above to see if I can understand them and then test them. Thanks again everyone for the help! I am a little confused. $password can be anything. It is actually a string from a login GUI. I take this string and use it as the pattern to search for. So if a users stored password is "AutoITRocks" and they enter (for example) "Auto" in the password field of the GUI, it returns a true value based on the partial match. Edited January 15, 2015 by kudrow
mikell Posted January 15, 2015 Posted January 15, 2015 The string it is evaluating is a text file containing other data including a password. I am searching the entire data file to see if $password exist in it. So "==" will obviously don't do the trick, either StringInStr because it will match "pa" in "password" - requirements quite clear in OP's post #3
JohnOne Posted January 15, 2015 Posted January 15, 2015 $Password = "pass" $data = " big sting of data including the pissward password inside as well as the shorter pass word" If StringInStr($data, " " & $Password & " ") Then MsgBox(0, "Woo", "Hoooo!") EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Moderators SmOke_N Posted January 15, 2015 Moderators Posted January 15, 2015 (edited) Maybe: StringRegExp($string, "\b\Q" & $password & "\E\b") ? Edit: or exact match: StringRegExp($string, "^\b\Q" & $password & "\E\z") Edited January 15, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
kudrow Posted January 15, 2015 Author Posted January 15, 2015 Where's your pattern? looks like you just need StringInStr. The pattern is $password
guinness Posted January 15, 2015 Posted January 15, 2015 I am going to throw that out there, look in my signature for PasswordValid to check the validity of the password too e.g. enough digits, lowercase chars etc. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
kudrow Posted January 15, 2015 Author Posted January 15, 2015 $Password = "pass" $data = " big sting of data including the pissward password inside as well as the shorter pass word" If StringInStr($data, " " & $Password & " ") Then MsgBox(0, "Woo", "Hoooo!") EndIf Ok so this is looking for spaces on either side of the variable $password correct?
JohnOne Posted January 15, 2015 Posted January 15, 2015 Yes, I suppose it's a rather poor example AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kylomas Posted January 15, 2015 Posted January 15, 2015 (edited) Yes, I suppose it's a rather poor example No it's not. It is essentially the same as Stringregexp($data, '\b\Q' & $Password & '\E\b') as suggested earlier. The OP's problem was not making the match restrictive enough. kylomas Edited January 15, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
kudrow Posted January 15, 2015 Author Posted January 15, 2015 I am going to throw that out there, look in my signature for PasswordValid to check the validity of the password too e.g. enough digits, lowercase chars etc. Got it! I will be using this for the registration side of the script! Thank you!
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