Jump to content

Checking credentials trough remote file


Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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]
Link to comment
Share on other sites

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
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...