Andreik Posted November 25, 2009 Share Posted November 25, 2009 I want to create a database to keep user accounts using SQLite functions. I want to can add and get info about users like in this example that use a simple text file as database. Can someone help me? expandcollapse popup$MAIN = GUICreate("UserDB",155,55) $USER = GUICtrlCreateInput("",5,5,100,20) $PASS = GUICtrlCreateInput("",5,30,100,20) $ADD = GUICtrlCreateButton("ADD",110,5,40,20) $GET = GUICtrlCreateButton("GET",110,30,40,20) GUISetState(@SW_SHOW,$MAIN) While True $MSG = GUIGetMsg() Switch $MSG Case -3 Exit Case $ADD $USR = GUICtrlRead($USER) $PWD = GUICtrlRead($PASS) $EXIST = GetUser($USR) $DB = FileOpen("mydb.db",1) If Not $EXIST Then FileWriteLine($DB, $USR & @TAB & $PWD) FileClose($DB) GUICtrlSetData($USER,"") GUICtrlSetData($PASS,"") Case $GET $RESULT = GetUser(GUICtrlRead($USER),1) If Not IsArray($RESULT) Then GUICtrlSetData($USER,"No user found") GUICtrlSetData($PASS,"") Else GUICtrlSetData($USER,$RESULT[1]) GUICtrlSetData($PASS,$RESULT[2]) EndIf EndSwitch Sleep(10) WEnd Func GetUser($USER,$MODE=0) Local $DB = FileOpen("mydb.db",0) Local $EXIST = False Local $INDEX = 1 While True $LINE = FileReadLine($DB,$INDEX) If @error Then ExitLoop $SPLIT = StringSplit($LINE,@TAB) If $SPLIT[1] = $USER Then ;User already in DB If $MODE = 1 Then Return $SPLIT Else $EXIST = True ExitLoop EndIf EndIf $INDEX += 1 WEnd FileClose($DB) Return $EXIST EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
99ojo Posted November 25, 2009 Share Posted November 25, 2009 (edited) I want to create a database to keep user accounts using SQLite functions. I want to can add and get info about users like in this example that use a simple text file as database. Can someone help me? expandcollapse popup$MAIN = GUICreate("UserDB",155,55) $USER = GUICtrlCreateInput("",5,5,100,20) $PASS = GUICtrlCreateInput("",5,30,100,20) $ADD = GUICtrlCreateButton("ADD",110,5,40,20) $GET = GUICtrlCreateButton("GET",110,30,40,20) GUISetState(@SW_SHOW,$MAIN) While True $MSG = GUIGetMsg() Switch $MSG Case -3 Exit Case $ADD $USR = GUICtrlRead($USER) $PWD = GUICtrlRead($PASS) $EXIST = GetUser($USR) $DB = FileOpen("mydb.db",1) If Not $EXIST Then FileWriteLine($DB, $USR & @TAB & $PWD) FileClose($DB) GUICtrlSetData($USER,"") GUICtrlSetData($PASS,"") Case $GET $RESULT = GetUser(GUICtrlRead($USER),1) If Not IsArray($RESULT) Then GUICtrlSetData($USER,"No user found") GUICtrlSetData($PASS,"") Else GUICtrlSetData($USER,$RESULT[1]) GUICtrlSetData($PASS,$RESULT[2]) EndIf EndSwitch Sleep(10) WEnd Func GetUser($USER,$MODE=0) Local $DB = FileOpen("mydb.db",0) Local $EXIST = False Local $INDEX = 1 While True $LINE = FileReadLine($DB,$INDEX) If @error Then ExitLoop $SPLIT = StringSplit($LINE,@TAB) If $SPLIT[1] = $USER Then ;User already in DB If $MODE = 1 Then Return $SPLIT Else $EXIST = True ExitLoop EndIf EndIf $INDEX += 1 WEnd FileClose($DB) Return $EXIST EndFunc Hi, with your example you store Usernames and their passwords. This is working. It's not clear, what is your problem? Do you want to store more information? If yes have a look at line If Not $EXIST Then FileWriteLine($DB, $USR & @TAB & $PWD) If you want to store more data, just change line and add more 'fields' and some more Inputfields. ;-)) Stefan Edited November 25, 2009 by 99ojo Link to comment Share on other sites More sharing options...
Zedna Posted November 25, 2009 Share Posted November 25, 2009 There are examples for SQLite in Autoit's helpfile. Don't hesitate and go and read them. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now