I like the idea behind your script so I upgraded it to use sqlite and and now its 20% cooler.
#cs ----------------------------------------------------------------------------
AutoIt Version: 1.0
Author: pieeater
Script Function:
Allows you to force the user to have spacific information before they can enter
another part of your script... if you use it right. Examples will be provided
#ce ----------------------------------------------------------------------------
; #Function Names#===================================================================================
; _login()
; _createAccount()
;please leave suggested functions and i will try my best to add them in the future :D
; ===================================================================================================
#include-once
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#include <File.au3>
#include <Array.au3>
#include <SQLite.au3>
Global $SQL = False, $TABLES[2] = ["USERS", "DATA"], $DB, $NOUPDATE = False, $DATABASE = @DesktopDir & "\Login Data"
#cs #FUNCTION# ====================================================================================================================
Name...........: _login()
Description ...: Opens a gui allowing the user to input an username and an password
Syntax.........: _login($flag)
Parameters ....: $flag = 0
$flag = 1
Returns........: $flag = 0
0 = login succesful
1 = login failed
2 = Username Non-Existant
$flag = 1
Returns a string containing the username if succesful, if unsuccesful returns 1, if no file returns 2
Author ........: pieeater
Remarks .......: this will only find the username and password if the file is in the same directory as script
Example .......: _login()
#ce ===============================================================================================================================
Func _login
($flag = 0)
If Not $SQL Then _INIT
()
Local $exit2 = 1, $WIN = True
#region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Login", 183, 153, -1, -1, BitOR($WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
Local $Exit = GUICtrlCreateIcon("shell32.dll", 28, 160, 8, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP))
Local $Label1 = GUICtrlCreateLabel("Username", 32, 8, 52, 17)
Local $Label2 = GUICtrlCreateLabel("Password", 32, 64, 50, 17)
Local $Input1 = GUICtrlCreateInput("", 32, 32, 121, 21)
Local $Input2 = GUICtrlCreateInput("", 32, 88, 121, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
Local $LoginBtn = GUICtrlCreateButton("Login", 30, 120, 125, 25, $WS_GROUP)
GUICtrlCreatePic("", 1, 1, 185, 155, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
WinSetTrans($Form1, "", 220)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While $Exit <> 0
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case $Exit
$exit2 = 0
GUIDelete($Form1)
Return 1
Case $LoginBtn
If 0 = StringCompare(BinaryToString(_GetDataEx
("DATA", "USER")), BinaryToString(GUICtrlRead($Input1)), 1) Then
If 0 = StringCompare(BinaryToString(_GetDataEx
("DATA", "PSWD")), BinaryToString(GUICtrlRead($Input2)), 1) Then
MsgBox(0, "Win", "you win:D")
$WIN = 0
If $flag == 0 Then Return 0
If $flag == 1 Then Return GUICtrlRead($Input1)
GUIDelete($Form1)
EndIf
If $WIN <> 0 Then
MsgBox(0, "Error", "Password is wrong")
GUICtrlSetData($Input1, "")
GUICtrlSetData($Input2, "")
ControlFocus("Login", "", $Input1)
EndIf
Else
MsgBox(48, "Error", "UserName is not in the database!")
GUIDelete($Form1)
Return 2
EndIf
EndSwitch
WEnd
EndFunc ;==>_login
#cs #FUNCTION# ====================================================================================================================
Name...........: _createAccount()
Description ...: Adds a user account to the file "Accounts.crypt"
Syntax.........: _createAccount( $_uName, $_pWord)
Parameters ....: $_uName = Username.
$_pWord = Password.
Returns........: 0 = Success
-1 = Username exists
Author ........: pieeater
Example .......: _createAccount( "username", "password")
#ce ===============================================================================================================================
Func _createAccount
($_uName, $_pWord)
If Not $SQL Then _INIT
()
_SetDataEx
($_uName, "DATA", "USER")
_SetDataEx
($_pWord, "DATA", "PSWD")
Return 1
EndFunc ;==>_createAccount
#region - Internal -
Func _INIT
()
If Not _STARTUP
($DATABASE, $TABLES) Then
MsgBox(16, "SQLite Error", "SQLite was not initialized correctly, please check for problems in function _STARTUP()", 5)
Exit
Else
$SQL = True
EndIf
EndFunc ;==>_INIT
Func _STARTUP
($DATABASE, $TABLES)
If _Crypt_Startup() = @error Then MsgBox(16, "ERROR", "CRYPT ERROR!!!")
If Not _SQLite_Startup() Then MsgBox(16, "ERROR", "SQLITE ERROR!!!")
If Not FileExists($DATABASE) Then
$DB = _SQLite_Open($DATABASE)
If @error Then Return 0
For $i = 0 To UBound($TABLES) - 1
_SQLite_Exec($DB, "CREATE TABLE " & $TABLES[$i] & " (Address,Val1,Val2);")
Next
Return 2
Else
$DB = _SQLite_Open($DATABASE)
If @error Then Return 0
EndIf
Return 1
EndFunc ;==>_STARTUP
Func _SetDataEx
($Data, $Table, $Address, $UKEY = "SALT")
Local $Key, $CData
_Crypt_Startup()
$Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
$CData = _Crypt_EncryptData($Data, $Key, $CALG_USERKEY)
_DataAddEx
($Table, $Address, $CData)
If @error Then Return @error
_Crypt_DestroyKey($Key)
_Crypt_Shutdown()
Return 1
EndFunc ;==>_SetDataEx
Func _GetDataEx
($Table, $Address, $UKEY = "SALT")
Local $RData, $Key, $Data, $CData
_Crypt_Startup()
$Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
$RData = _DataQueryEx
($Table, $Address)
If Not $RData Then Return 0
$CDta = _Crypt_DecryptData($RData, $Key, $CALG_USERKEY)
If @error Then Return 0
Local $Data = BinaryToString($CDta)
If $Data = "" Then Return 0
_Crypt_DestroyKey($Key)
_Crypt_Shutdown()
Return $Data
EndFunc ;==>_GetDataEx
Func _DataAddEx
($Table, $Address, $Val1, $Val2 = "")
Local $Data
_SQLite_QuerySingleRow($DB, "SELECT Address FROM " & $Table & " WHERE Address='" & $Address & "'", $Data)
If $Data[0] <> "" Then; If there is an error here than its your fault... the data base doesn't exist
If $NOUPDATE Then Return 1
_SQLite_Exec($DB, "UPDATE " & $Table & " SET Val1='" & $Val1 & "', Val2='" & $Val2 & "' WHERE Address='" & $Address & "'")
Else
_SQLite_Exec($DB, "INSERT INTO " & $Table & " (Address,Val1,Val2) VALUES ('" & $Address & "','" & $Val1 & "','" & $Val2 & "');")
EndIf
Return 1
EndFunc ;==>_DataAddEx
Func _DataQueryEx
($Table, $Address, $Ar = False)
Local $Ret
If _SQLite_QuerySingleRow($DB, "SELECT * FROM " & $Table & " WHERE Address='" & $Address & "'", $Ret) == $SQLITE_OK Then
If $Ret[0] == "" Then
Return 0
Else
If $Ar Then Return $Ret
If $Ret[1] = "" Or $Ret[1] = ' ' Then Return 0
Return $Ret[1]
EndIf
EndIf
Return 0
EndFunc ;==>_DataQueryEx