Sign in to follow this  
Followers 0
marko001

Checking credentials trough remote file

4 posts in this topic

Hi all,

I'm interested in creating a tool that can check credentials remotely to retrieve if login/password is on a "white list" so to grant access to the program.

So mainly the user will insert username/password and press "Login"

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 157, 192, 124)
GUICtrlCreateLabel("Username", 16, 48, 52, 17)
$username = GUICtrlCreateInput("", 72, 46, 121, 21)
GUICtrlCreateLabel("Password", 16, 72, 50, 17)
$password = GUICtrlCreateInput("", 72, 70, 121, 21)
$login = GUICtrlCreateButton("Login", 14, 96, 179, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $login
            _checkCredentials($username,$password)
    EndSwitch
WEnd


Func _checkCredentials($username,$password)
    
EndFunc

The function _checkcredentials(...) should check a remote file

john,qwerty
peter,123456
William,1q2w3e
...,...

and check if the credentials are in the file. If YES, continue program, if NOT, exit.

I need a function similar to _readfile2Array from remote and check existence of the datas given by $username and $password.

Can you help me with this?

Thanks a lot,

Marco

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What do you mean by "remote"?

It depends on the way you can connect to the remote system. Is it another computer/server on a company network? Is it on the internet? Do you have access to the remote machine so you can install a "server" component? ...

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Marko001,

If you are in a LAN environment and you have access to the appropriate share you can use _FileReadToArray().

But then again I would not save the passwords in cleartext. Have a look at the _Crypt___() Functions in the helpfile.

If you are not in a LAN environment you'll need to write a client-server type of application. So lookup TCP___() Functions in the helpfile. In this case it is not less important that you use encryption.

:huh2:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I did it this way, it works perfectly but I don't like downloading the full list. Is there a way to avoid it?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


#include <file.au3>
#include <array.au3>


$s_CredentialPath = "http://www.mysite.com/credentials"
$s_CredentialSite = "Login_Pw_Session.txt"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 157, 192, 124)
GUICtrlCreateLabel("Username", 16, 48, 52, 17)
$username = GUICtrlCreateInput("", 72, 46, 121, 21)
GUICtrlCreateLabel("Password", 16, 72, 50, 17)
$password = GUICtrlCreateInput("", 72, 70, 121, 21)
$login = GUICtrlCreateButton("Login", 14, 96, 179, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $login
            $logtest = _checkCredentials(GUICtrlRead($username),GUICtrlRead($password),$s_CredentialPath,$s_CredentialSite)
            _testresult($logtest)

    EndSwitch
WEnd


Func _checkCredentials($username,$password,$path,$file)
    local $temp_file = @TempDir & "\sdfjsdflkjs.txt"
    local $hwnd = InetGet($path & "\" & $file, $temp_file)
    $countlines = _FileCountLines($temp_file)
    for $i = 1 to $countlines
        $line = FileReadLine($temp_file,$i)
        $string = StringSplit($line,",")
        if $username = $string[1] Then
            if $password = $string[2] Then
                Return 1
            Else
                return 0
            EndIf
        Else
        EndIf
    Next
EndFunc

Func _testresult($check)
    if $check = 1 Then
        msgbox(0,"OK", "Login OK")
    EndIf
    if $check = 0 Then
        msgbox(0,"NO!", "Failed")
    EndIf
EndFunc

And yes, avoiding password visibility should be a must

Edited by marko001

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
Sign in to follow this  
Followers 0