Jump to content

Recommended Posts

Posted

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?

Posted

$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
Posted (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
Next
M23 Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Posted

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

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

 

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

  • Moderators
Posted (edited)

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.

Posted

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

Posted
$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?

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

Posted

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!

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
×
×
  • Create New...