Jump to content

not so safe login UDF


Recommended Posts

im making a login UDF that makes u login befor you start the script but i cant figure out how to get the password from the ini file im using. heres my code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <Array.au3>
Global $a=IniReadSectionNames("accounts.ini")
Global $newuserinput = GUICtrlCreateInput("", 8, 40, 185, 21)
Global $newupassinput = GUICtrlCreateInput("", 8, 96, 185, 21, $ES_PASSWORD)
Func _login()
    $NewUser = GUICreate("New username", 209, 188, -1, -1)
    $newuserinput = GUICtrlCreateInput("", 8, 40, 185, 21)
    $newupassinput = GUICtrlCreateInput("", 8, 96, 185, 21, $ES_PASSWORD)
    $Createnewuser = GUICtrlCreateButton("&OK", 14, 128, 75, 25, $BS_NOTIFY)
    $Cancelnewuser = GUICtrlCreateButton("&Cancel", 111, 128, 75, 25, $BS_NOTIFY)
    $EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
    $newusername = GUICtrlCreateLabel("Enter New Username", 8, 16, 105, 17)
    $switchlogin = GUICtrlCreateButton( "&Login", 55, 160, 100, 25)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            case $cancelnewuser
                Exitloop
            Case $GUI_EVENT_CLOSE
                Exit
            Case $createnewuser
                _Create_New_User()
            Case $switchlogin
                _Login_menu()
        EndSwitch
    WEnd
EndFunc
Func _Create_New_User()
    If _ArrayFindAll($a,GUICtrlRead($newuserinput),1) Then
        IniWriteSection("accounts.ini",GUICtrlRead($newuserinput), "password = " & GUICtrlRead($newupassinput))
        MsgBox( 4096, "User Doesn't Exist", "success")
    Else
        MsgBox( 4096, "Username Found", "Imposter! That username already exists!")
    EndIf
EndFunc
Func _Login_menu()
    $gui=GUICreate("Login", 209, 188, -1, -1)
    $userinput = GUICtrlCreateInput("", 8, 40, 185, 21)
    $passinput = GUICtrlCreateInput("", 8, 96, 185, 21, $ES_PASSWORD)
    $Enter = GUICtrlCreateButton("&OK", 14, 128, 75, 25, $BS_NOTIFY)
    $Cancel = GUICtrlCreateButton("&Cancel", 111, 128, 75, 25, $BS_NOTIFY)
    $Labelpass = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17, 0)
    $username = GUICtrlCreateLabel("Enter Username", 8, 16, 105, 17)
    GUISetState(@SW_SHOW)
    While 1
        $a=IniReadSectionNames("accounts.ini")
        $b=IniReadSection("accounts.ini", GUICtrlRead($passinput))
        $nMsg=GUIGetMsg()
        Switch $nMsg
            Case $Cancel
                Exit
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Enter
                If _ArraySearch($a, GUICtrlRead($userinput),1) And _ArraySearch($b,GUICtrlRead($passinput)) Then   ;<===== this is where im having trouble
                    Exit
                    _Success()
                Else
                    MsgBox(4096,"Access denied","Please Try Again")
                EndIf
        EndSwitch
    WEnd
EndFunc

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

Reading the accounts.ini file every message loop on the login window is way more load than is needed. Only read it after the user presses the OK button.

I'd opt for simply trying to iniRead(), somewhat like this:

While 1
        $nMsg=GUIGetMsg()
        Switch $nMsg
            Case $Cancel
                Exit
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Enter
                $a = IniRead("accounts.ini", GUICtrlRead($userinput), "password", -395724618)
                If $a <> -395724618 And $a == GUICtrlRead($passinput) Then   ;<===== this is where im having trouble
                    _Success()
                Else
                    MsgBox(4096,"Access denied","Please Try Again")
                EndIf
        EndSwitch
    WEnd

If a user happened to set their password to "-395724618" they're screwed of course...

Edited by bwochinski
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...