Jump to content

Simple authentication method


Pottery
 Share

Recommended Posts

I know there are far better ways to go about this but I created my own little authentication method and thought that I'd share it.

The site I used, t35.com, is free.

#include <FTP.au3>
#include <INet.au3>

Func fLogin()
    $Text = _INetGetSource('http://username.t35.com/account/' & GUICtrlRead($Input1) & '.txt') ; Go to the username file if it exists
    If StringInStr($Text, 'pw' & GUICtrlRead($Input2) & 'pw') Then ; I put pw on both sides so if for example the pw is bob, the user could just put b
        GUISetState(@SW_HIDE, $Form1)
        fMain()
    Else
        MsgBox(2064, 'Error', 'Invalid account information; login failed.') ; If the username.txt isn't found.
    EndIf
EndFunc



Func fRegister()
    $Open = _FTPOpen('MyFTP')
    $Connect = _FTPConnect($Open, 'ftp.t35.com', 'username.t35.com', 'password')
    _INetGetSource('http://username.t35.com/account/' & GUICtrlRead($Input3) & '.txt')
    If @error Then ; @error means the username file doesn't exist
        If GUICtrlRead($Input4) = GUICtrlRead($Input5) Then
            FileWriteLine(GUICtrlRead($Input3) & '.txt', 'pw' & GUICtrlRead($Input4) & 'pw')
            FileWriteLine(GUICtrlRead($Input3) & '.txt', 'em' & GUICtrlRead($Input6) & 'em')
            _FTPPutFile($Connect, GUICtrlRead($Input3) & '.txt', '/account/' & GUICtrlRead($Input3) & '.txt')
            Do
                Sleep(10)
            Until _INetGetSource('http://username.t35.com/account/' & GUICtrlRead($Input3) & '.txt') = Not @error ; Until the file exists on the site
            FileDelete(GUICtrlRead($Input3) & '.txt')
            MsgBox(64, 'Registered', 'Thanks for registering! You may now login.')
        Else
            MsgBox(2064, 'Error', 'The passwords you entered do not match.')
        EndIf
    Else
        MsgBox(2064, 'Error', 'The username you entered is not available.')
    EndIf
    _FTPClose($Open)
EndFunc

And thanks Jos for not helping me and making me come up with this, no sarcasm intended.

Link to comment
Share on other sites

This is how I had my GUI setup:

$Form1 = GUICreate("Login", 251, 266, 192, 114)
GUISetFont(11, 400, 0, "Tahoma")
$Group1 = GUICtrlCreateGroup("Login", 8, 8, 233, 97, $BS_RIGHT)
GUICtrlSetColor(-1, 0x000000)
$Label1 = GUICtrlCreateLabel("Username", 16, 32, 71, 22)
$Input1 = GUICtrlCreateInput("", 112, 32, 121, 21)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Label2 = GUICtrlCreateLabel("Password", 16, 56, 65, 22)
$Input2 = GUICtrlCreateInput("", 112, 56, 121, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Button1 = GUICtrlCreateButton("Login", 160, 80, 75, 17, $WS_GROUP)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Register", 8, 112, 233, 145, $BS_RIGHT)
$Label3 = GUICtrlCreateLabel("Username", 16, 136, 71, 22)
$Label4 = GUICtrlCreateLabel("Password", 16, 160, 65, 22)
$Label5 = GUICtrlCreateLabel("Confirm", 16, 184, 54, 22)
$Label6 = GUICtrlCreateLabel("Email", 16, 208, 37, 22)
$Input3 = GUICtrlCreateInput("", 112, 136, 121, 21)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Input4 = GUICtrlCreateInput("", 112, 160, 121, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Input5 = GUICtrlCreateInput("", 112, 184, 121, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Input6 = GUICtrlCreateInput("", 112, 208, 121, 21)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Button2 = GUICtrlCreateButton("Register", 160, 232, 75, 17, $WS_GROUP)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            fLogin()
        Case $Button2
            fRegister()

    EndSwitch
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

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