Jump to content

Login validation with INI


Recommended Posts

Hello, I am a bit of a beginner in programming with autoit, please could you help me, I am a bit stuck, I am doing a login with user and password validation, it works very well with iniread, but it can only read a single line of the ini file when you want to add more users or passwords to the ini file continues to read me only the first line and does not validate the rest of the data, and I tried with inireadsection, but there is the problem I am not very clear on how to use it and I looked for an example and tried but I cannot make it work please for whom can help thank you very much

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>


Contra()
Prin ()

Func Contra()

Global $Login = GUICreate("Login", 441, 251, -0, -0)
GUISetFont(12, 400, 2, "Times New Roman")
GUISetBkColor(0xFFFFFF)
$Label = GUICtrlCreateLabel("Usuario", 280, 40, 95, 24, $SS_CENTER)
$usur = GUICtrlCreateInput("", 248, 80, 169, 27)
GUICtrlSetBkColor(-1, 0xC8C8C8)
$Pass = GUICtrlCreateInput("", 248, 168, 169, 27, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
GUICtrlSetBkColor(-1, 0xC8C8C8)
$Labe2 = GUICtrlCreateLabel("Contraseña", 288, 128, 95, 23, $SS_CENTER)
$Button1 = GUICtrlCreateButton("Login", 136, 208, 177, 33)
GUICtrlSetCursor (-1, 0)
$Pic1 = GUICtrlCreatePic("Logo.JPG", 8, 24, 233, 169)
Dim $Login_AccelTable[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($Login_AccelTable)
GUISetState(@SW_SHOW)

While 1
   $a = wingetpos("Login")
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $Button1
            Global $UserInput = GUICtrlRead($usur)
            Global $Passinput = GUICtrlRead($Pass)

if $UserInput = iniread ("User.ini", "Usuario",  1, Default) And $Passinput = iniread ("Pass.ini", "Contraseñas",  1, Default) Then
Prin ()
 Else
     MsgBox(0,"ERROR","Verifique usuario y contraseña")

EndIf
    EndSwitch
WEnd
 EndFunc

  Func Prin ()
GUISetState(@SW_HIDE,$Login)
$VIngreP = GUICreate("Ingreso", 602, 202, 215, 168)
GUISetBkColor(0xFFFFFF)
$Label1 = GUICtrlCreateLabel("! Bienvenido", 16, 8, 88, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman")
$Label2 = GUICtrlCreateLabel($UserInput, 104, 8, 61, 23, BitOR($SS_CENTER,$SS_RIGHTJUST), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

EndFunc

 

Edited by Hemrry
Link to comment
Share on other sites

I would suggest you change your ini file to make user name the key, and password the value.  Then you can read ini just once to get the right password associated with the user name.

Link to comment
Share on other sites

@Hemrry

if you dont know how to use IniReadSection see below:

$UserIni = IniReadSection("User.ini", "Usuario")
                $PassIni = IniReadSection("Pass.ini", "Contraseñas")
                For $i = 1 To $UserIni[0][0] + $PassIni[0][0]
                    if $i > $UserIni[0][0] Or $i > $PassIni[0][0] Then
                        if $i = $UserIni[0][0] + $PassIni[0][0] Then
                            MsgBox(64, "ERROR", "ERROR")
                        EndIf
                    Else
                        if $UserInput = $UserIni[$i][1] And $Passinput = $PassIni[$i][1] Then ; check every line if it's match [$UserInput]
                            Prin()
                        EndIf
                    EndIf

                Next

User.ini File:

[Usuario]
1=name1
2=name2
3=name3
4=name4

Pass.ini File:

[Contraseñas]
1=de
2=rrr
3=54
4=eed

 

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

Having all Userids and Passwords in plain text in simple text files isn't very secure, is it?
I hope your security requirements are equal to the security provided by this setup ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

At the very least, store the userid and a strong hash of "userid & passphrase" possibly with some salt. This way Eve can't easily impersonate any Alice or Bob.

Well in theory since, as you should know, AutoIt scripts even "compiled" aren't immune to reverse-engineering.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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