Jump to content
Sign in to follow this  
kudrow

Going Crazy

Recommended Posts

kudrow

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?

Share this post


Link to post
Share on other sites
kudrow

$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".

Share this post


Link to post
Share on other sites
Melba23

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
Next
M23 Edited 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Valuater

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

NEWHeader1.png

Share this post


Link to post
Share on other sites
jguinch

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+

Share this post


Link to post
Share on other sites
Valuater

I truly believe that the == is the fastest absolute test.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
kudrow

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 by kudrow

Share this post


Link to post
Share on other sites
mikell

 

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

Share this post


Link to post
Share on other sites
JohnOne

$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.

Share this post


Link to post
Share on other sites
SmOke_N

Maybe:

StringRegExp($string, "\b\Q" & $password & "\E\b")

?

Edit:

or exact match:

StringRegExp($string, "^\b\Q" & $password & "\E\z")
Edited 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.

Share this post


Link to post
Share on other sites
kudrow

Where's your pattern?

looks like you just need StringInStr.

The pattern is $password

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
kudrow
$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?

Share this post


Link to post
Share on other sites
kylomas

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 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

Share this post


Link to post
Share on other sites
kudrow

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!

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Deye
      By Deye
      Hi,
      I want to add any needed conditions to the StringRegExp command so it can pull out only  "File.au3", "WinAPIFiles.au3", "Test.bmp" into the array
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $sFile = FileRead(@ScriptFullPath) $aResults = StringRegExp($sFile, "(?i)(FileInstall\s*|include\s*)(.*)", 3) _ArrayDisplay($aResults) Thanks In Advance
      Deye
    • FroVN
      By FroVN
      i have a text : <Name>Jonh</Name>.<Age>15</Age>
      how i can get Jonh and 15 in one stringregexp? pls give me example
    • therks
      By therks
      I'm looking for a regex genius, cus I'm stumped when it comes to assertions.
      So what I have now, is this regular expression: ([^|=]+)=([^|]+)
      It takes a string (user input) of keys=values separated by pipes (ie: "param=value|param=value") and splits them into an array.
      Example:
      $vParamData = 'example=value|fruit=apple|phrase=Hello world' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; Result ; [0] => example ; [1] => value ; [2] => fruit ; [3] => apple ; [4] => phrase ; [5] => Hello world So that's working fine, but I'm wondering if there's also a way I could have this capture escaped pipes instead of splitting by them.
      ie:
      $vParamData = 'pipe test=this \| is a pipe|example=value' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; I'm getting this: ; [0] => pipe test ; [1] => this \ ; [2] => example ; [3] => value ; But I'd like a result like this: ; [0] => pipe test ; [1] => this \| is a pipe ; [2] => example ; [3] => value Is there some pattern that would accomplish this, or am I better off parsing it some other way?
    • Robinson1
      By Robinson1
      Well the plan is to use the power of regular expressions engine of AutoIT for patching binary data.
      Something like this: StringRegExp( $BinaryData,  "(?s)\x55\x8B.."
       
      <cut> ... Okay straight to question/problem
      ... certain bytes that are in the range from 0x80 to 0xA0 won't match.
      Hmm seem to be a char encoding problem. In detail these are 27 chars: 0x80, 0x82~8C, 0x8E, 0x91~9C, 0x9E,0x9F
      Here's a small code snippet to explore / explain this problem:
      #include "StringConstants.au3" $TestData = BinaryToString("0x7E7F808182") ;Okay $match = StringRegExp( $TestData ,'\x7E' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x7F' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x80' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x81' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x82' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;~ output: ;~ @extended = 2 $match = ;~ @extended = 3 $match = ;~ @extended = 0 $match = 1 ;~ @extended = 5 $match = ;~ @extended = 0 $match = 1 Hmm what to do? Go back and use the 'numberstring monster' implementation or just omit that range of 'unsafe bytes'. What is the root of this problem?
      Any idea how to fix this?
       
      Update: Okay I know a byte is not a character.
      But StringRegExp operates on String and so character level.
      Okay as long as you stay at Ansi encoding and only use /x00 - /X7F in the search pattern using  StringRegExp works well to search for binary data.
      What bytes can be matched that are in the range from /X7F - /xFF is also depending on the code page.
      So this avoid to search for bytes in the range from 0x80-0xa0 only applies to Germany.
      I just change this country setting:

      to Thai and now near all bytes from /X7F - /xFF fails to match.
    • Carm01
      By Carm01
      Hello,
      I have spent the past day fooling with StringRegExp to no avail attempting to get what would be a simple solution to an issue using StringRegExp.
      I will post the code in a sec. The string 'Java x Update y' where x and y are numeric values ONLY if a letter is mixed in anywhere then it should fail. I have been able to successfully deal with the x value so if x = 1234 or a1234 or 1a234 or 1234a would result in a fail if 'a' was in the string. However, when y = 1a234 then I get an output of 1 and when y = 1234a then the output = 1234 when both should fail. I am probably overlooking something simple and in looking through all the material and experimenting I am unable to figure it out and my experience with stringregexp and trying to find examples of this proved difficult. If someone could assist or point me to a thread ? Here is my code ; prob a simple fix. I am also trying to avoid white spaces.
      Thanks in advance
      #include <array.au3> $aArray = StringRegExp('Java 3009 Update 1a21', '(?i)Java (\d+) Update (\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Exit _ArrayDisplay($aArray)  
×