Jump to content

Recommended Posts

Posted (edited)

here is a script i put together, the last login UDF post i made was badly written and i decided to reattempt the idea because i got bored :)

this script is much more reliable and a thousand times less confusing :mellow: anyways here are the examples

;using flag 0
 
#include "Login.au3"
 
_createAccount("pieeater", "hello");Creates the account to the file "Accounts.crypt"
 
$valid = _login(0);Starts the login
 
If $valid = 1 Then;Checks the return of the login
    MsgBox(0, "Win", "you got logged in! good job!");if your login was succesful then this will run
Else
    MsgBox(0, "Lose", "you are NOT logged in!");if you failed at the login this will run
EndIf

Example 2

;using flag 1
 
_createAccount("pieeater", "hello");Creates the account to the file "Accounts.crypt"
 
$uName = _login(1);Starts the login
 
If $uName <> 1 Then;Checks the return of the login
    MsgBox(0, "Win", "you got logged in! Your username is " & $uName & "!");if your login was succesful then this will run
Else
    MsgBox(0, "Lose", "you are NOT logged in!");if you failed at the login this will run
EndIf

i know i included it in the UDF but flag 0 is used if you only want to know if the login was succesful, and flag 1 is used if you want the username returned to.

please leave suggestions since i only have 2 functions in this UDF and i would like to add to it whenever i get a chance :)

hope you like it,

pieeater

Login.au3

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Posted (edited)

Nice, I once found I gui example here and started doing stuff with it and ended up with and it sort of got out of hand and I stopped working on it, but when you run it, if you right click the help icon, a little menu comes down and if you click that, you get the login box.

Edited by THAT1ANONYMOUSEDUDE
Posted (edited)

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
Edited by THAT1ANONYMOUSEDUDE
Posted (edited)

thanks for the upgrade, i've never used sqlite so ill have to have a look at the code to understand it but thanks anyway :mellow:

Don't worry about understanding SQL, the script functions that were put in your script make it like 50% easier than using the crypt functions you originally had.

These are the two only functions that are relevant and matter-

_SetDataEx($Data, $Table, $Address, $UKEY = "SALT")

_GetDataEx($Table, $Address, $UKEY = "SALT")

I paste those functions to every script I make that requires managing data, and it ads a layer of difficulty by using the database, which a newbie probably won't understand right away, especially since the data in it is encrypted.

And if you'd like to encrypt stuff even more, look into CryptProtectData API, it encrypts stuff so only the user who encrypted it can fetch it back.

A have a UDF for it here somewhere in my script bank folder, gotta look for it...

Edited by THAT1ANONYMOUSEDUDE

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...