Blank517

SQLite login

5 posts in this topic

Hi, I would like to make a login script with SQLite. The database looks like this:

_SQLite_Exec(-1, "CREATE TABLE Users (id INT(8) NOT NULL, username VARCHAR(30) NOT NULL, password VARCHAR(255) NOT NULL, permission INT(8) NOT NULL, PRIMARY KEY (id)); CREATE UNIQUE INDEX 'user_name_unique' ON 'Users' ('username' );")
_SQLite_Exec(-1, "INSERT INTO Users(id, username, password, permission) VALUES ('0', 'default', 'password', '0');")


theoretically I should make a query in this way, right?

_SQLite_Query (-1, "SELECT id FROM Users WHERE username = '" & $ Recv [1] & "' AND password = '" & $ Recv [2] & "';", $ hQuery)


but then I do not know how to know if you have found the 'id'

Share this post


Link to post
Share on other sites



Are you checking against $SQLITE_OK? Look at the example for _SQLite_Query in the help file.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Just now, JLogan3o13 said:

Are you checking against $SQLITE_OK? Look at the example for _SQLite_Query in the help file.

I already tried but i think that $SQLITE_OK checks only if command was successful

Share this post


Link to post
Share on other sites

I guess I'm not understanding what you are asking then, it might be helpful to post all of your code. If I create a table based on the inputs you're looking for, like so:

#include <SQLite.au3>
#include <SQLite.dll.au3>

Local $hDB, $myDBase = @TempDir & "\Test.tmp", $dllSQLite = @TempDir & "\sqlite.dll"

Local $sDLL = _SQLite_Startup($dllSQLite, False, 1)
    If @error Then
        ConsoleWrite("Failed with error: " & @error & @CRLF)
        Exit(-1)
    EndIf

$hDB = _SQLite_Open($myDBase)
    If $hDB = -1 Then Exit(MsgBox(0, "", "Error"))

    If $SQLITE_OK <> _SQLite_Exec($hDB, "CREATE TABLE Test ('ID', 'Username', 'Password', 'Permission');") Then
        MsgBox(0, "", "Error from TableCreate: " & _SQLite_ErrCode() & ". " & _SQLite_ErrMsg())
        Exit (-1)
    Else
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20418','Billy', 'Password1!', 'Administrator');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20419','Joe', 'Password2!', 'Operator');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20420','Jim', 'Password3!', 'User');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20421','Bob', 'Password4!', 'CEO');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20422','Sally', 'Password5!', 'Manager');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20423','Susie', 'Password6!', 'Mailroom');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20424','Sandra', 'Password7!', 'Secretary');")
    EndIf

_SQLite_Close()
_SQLite_Shutdown()

and then run a query against the values I've inserted, like this:

#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Local $Recv[2] = ["Jimmy", "Password1!"], $hQuery, $aRow, $sMsg
Local $hDB, $myDBase = @TempDir & "\test.tmp", $dllSQLite = @TempDir & "\sqlite.dll"

Local $sDLL = _SQLite_Startup($dllSQLite, False, 1)
    If @error Then
        ConsoleWrite("Failed with error: " & @error & @CRLF)
        Exit(-1)
    EndIf

$hDB = _SQLite_Open($myDBase)
    If $hDB = -1 Then Exit(MsgBox(0, "", "Error"))

_SQLite_Query ($hDB, "SELECT id FROM Test WHERE username = '" & $Recv [0] & "' AND password = '" & $Recv [1] & "';", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $sMsg &= $aRow[0]
    WEnd

    MsgBox($MB_SYSTEMMODAL, "SQL Query", (($sMsg = "") ? "Failed to return ID" : $sMsg))

_SQLite_Close()
_SQLite_Shutdown()

It will tell me if the ID is not found.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@JLogan3o13 I love youuuu <3

You solved my problem, I didn't understand how to correctly use _SQLite_Query with _SQLite_FetchData...

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

  • Similar Content

    • kawliga751
      By kawliga751
      I am trying to script the opening of multiple tabs in IE with each tab having a separate login/password. I have been able to make a successful script that will open 3 separate IE sessions with the correct webpage and login or a script that will open 3 tabs in one session (which I want) but will not login. I have tried _IECreate, IEAttach etc. This is the script I am currently using . 
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/AAAA/index.htm') ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) Call ("YYYYYYYSignIn") Func YYYYYYYSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/xxxxxxx/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc Call ("xxxxxxxSignIn") Func xxxxxxxSignIn () __IENavigate($oIE, "https://soa1gui.xxxxxxx.biz/gateway/NFServlet;jsessionid=1E3B8F6520DE0A1EC914A8ABB7E86341?NFH_MessageId=&NFH_Page=%2fpages%2fsearch%2fsearch.jsp", 1, 0x800) Local $domain = _IEGetObjByName ($oIE,"NF_CustomerID") Local $User_Name = _IEGetObjByName ($oIE,"NF_UserName") Local $Password = _IEGetObjByName ($oIE,"NF_Password") _IEFormElementSetValue ($domain, xxxxxxx") _IEFormElementSetValue ($User_Name, "xxxxxxx") _IEFormElementSetValue ($Password, "xxxxxxx") ;Send('{Enter}') EndFunc  
    • Fhelipe
      By Fhelipe
      Nothing More
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I am working on a script which read from a text file ( .txt ) and should import all the content in a SQLite3 DB, in order to execute some queries that should be difficult to execute on a text file.
      So, I was looking for something very very fast, because the file could be very large ( I don't know exaclty how much can became big, but I know a lot of rows, it's a log file ... )
      I found the "Import method", but I don't know If I can implement it in a query ( @jchd, it's your turn!  )
      Do you know some methods that I can implement in my script to have a very very fast import of thousands and thousands rows in a SQLite3 DB?
      Thanks a lot
      Francesco
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to use again SQLite in AutoIt, and I've again an issue: I can't startup SQLite...
      Can you please show me the way to set the enviornment for a SQLIte usage in AutoIt? Step by step, I'll follow your suggestion(s).

      Thanks for everyone will reply!

      Francesco