Sign in to follow this  
Followers 0
Fhelipe

Login System Using Autoit And MYSQL

2 posts in this topic

#1 ·  Posted (edited)

Nothing More

Edited by Fhelipe

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hi @Fhelipe.

I'm not sure if you realize MySQL requires a server.

I've made an example in SQLite, however it's almost the same with the queries for MySQL.

I know the passwords SHOULD be hashed, but this is just a bare bones example.

#include <SQLite.au3>
#include <Array.au3>

$sSQLite = _SQLite_Startup("sqlite3.dll")
If @error<>0 Then Exit MsgBox(0, "", "SQLite Error", "SQLite3.dll Can't be Loaded!")
$hSQLiteDB = _SQLite_Open(@ScriptName&".sqlite3")
If @error<>0 Then Exit MsgBox(0, "", "Can't open or create a Database!")
_SQLite_Exec($hSQLiteDB, "CREATE TABLE IF NOT EXISTS `Users` (`ID` INTEGER PRIMARY KEY AUTOINCREMENT, `username` TEXT NOT NULL, `password` TEXT NOT NULL)")

;LOGIN example
$username = "Zummey"
$password = "xd90fe10"

Login($username, $password);will fail upon first run
If @error<>0 Then ConsoleWrite("Login failed"&@CRLF)

;inserts user if not exist
Create_User($username, $password)


_ArrayDisplay(Login($username, $password))

_SQLite_Close($hSQLiteDB)
_SQLite_Shutdown()

;Success:
;   Found: Array(ID, username)
;   Not Found: 0
;Failure: -1
Func Login($username, $password)
    Local $hQuery = 0
    Local $aRow = 0
    ;~ _SQLite_Query($hSQLiteDB, "INSERT INTO `Users` values ()"
    _SQLite_Query($hSQLiteDB, "SELECT `ID`, `username` FROM `Users` WHERE `username`=? AND `password`=? LIMIT 1", $hQuery)
    _SQLite_BindText($hQuery, 1, $username)
    _SQLite_BindText($hQuery, 2, $password)
    Local $iResult = _SQLite_FetchData($hQuery, $aRow)
    If $iResult = $SQLITE_OK Then Return $aRow
    Return SetError($iResult, 0, ($iResult=$SQLITE_DONE)?0:-1)
EndFunc

Func Create_User($username, $password)
    Local $hQuery = 0
    _SQLite_Query($hSQLiteDB, "INSERT INTO `Users` (`username`, `password`) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM `Users` WHERE `username`=?)", $hQuery)
    _SQLite_BindText($hQuery, 1, $username)
    _SQLite_BindText($hQuery, 2, $password)
    _SQLite_BindText($hQuery, 3, $username)
    Local $iRval_Step = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_step", "ptr", $hQuery)
    If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error
    $iChanges = _SQLite_Changes($hSQLiteDB)
    _SQLite_QueryFinalize($hQuery)
    If $iRval_Step=$SQLITE_DONE And $iChanges>0 Then Return 1
    Return SetError($iRval_Step, 0, 0)
EndFunc

;Source: https://autoit-script.ru/index.php?topic=21090.15#msg_124711
Func _SQLite_BindText($hQuery, $iRowID, $sTextRow)
    Local $iRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_bind_text16", _
            "ptr", $hQuery, _
            "int", $iRowID, _
            "wstr", $sTextRow, _
            "int", -1, _
            "ptr", NULL)
    If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error
    If $iRval[0] <> $SQLITE_OK Then
        Return SetError(-1, 0, $iRval[0])
    EndIf
    Return $iRval[0]
EndFunc

Hope this can help you getting started.

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

  • Similar Content

    • P3rsp3ctiv3
      By P3rsp3ctiv3
      Hello how can I send a {Enter} into the edit window ($cmd)? I tried it first with:
      GUICtrlSetData($cmd, "Line 1" + "{ENTER}")
      but it doesn´t work. Can someone help me please?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $Admin = GUICreate("Admin", 234, 168, 192, 229, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xB4B4B4) $exit = GUICtrlCreateButton("Close", 160, 136, 65, 25) $cmd = GUICtrlCreateEdit("",0, 0, 225, 137, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Candara") GUICtrlSetBkColor(-1, 0xE3E3E3) $cmd_clear = GUICtrlCreateButton("Clear", 9, 136, 65, 25) GUISetState(@SW_SHOW) HotKeySet("{f1}", CMD_1) HotKeySet("{f2}", CMD_2) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $exit GUIDelete($Admin) Exit EndSwitch WEnd Func CMD_1(); GUICtrlSetData($cmd, "Line 1" & "{ENTER}") GUICtrlSetData($cmd, "Line 2" & "{ENTER}") EndFunc Func CMD_2(); GUICtrlSetData($cmd, "Line 3" & "{ENTER}") GUICtrlSetData($cmd, "Line 4" & "{ENTER}") EndFunc
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • AdminC
      By AdminC
      $Imglocation = @ScriptDir&"\Image\testimg.bmp" _GDIPlus_Startup() Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap) Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap) Local $imgBits = DllStructCreate('dword[' & (DllStructGetData($imgSize, 'X') * DllStructGetData($imgSize, 'Y')) & ']') _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits)) ;_WinAPI_DisplayStruct($imgBits) MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) _GDIPlus_Shutdown()  
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz