Jump to content
Sign in to follow this  
Noviceatthis

InputBox Password

Recommended Posts

Noviceatthis

Hello all

I have just written this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Enter Password", 616, 133, 192, 124)
GUISetBkColor(0x000080)
$Label1 = GUICtrlCreateLabel("Enter Password", 8, 8, 598, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("", 8, 80, 593, 21)
$Button1 = GUICtrlCreateButton("Correct Password", 344, 64, 257, 49)
GUICtrlSetState($Button1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$v = 0

While 1
$Answer = GUICtrlRead($Input1)
If $Answer = "password" Then
If $v <> 0 Then
Sleep(20)
Else
func1()
EndIf
Else
$v = 0
EndIf



$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd


Func func1()
If $Answer = "password" Then
GUICtrlSetState($Input1, $GUI_HIDE)
$Input1 = GUICtrlCreateInput("password", 8, 80, 313, 21)
GUICtrlSetState($Button1, $GUI_SHOW)
$v = 2
EndIf
EndFunc   ;==>func1

My question is, how would i set it, so that when the password (in this case password) has already been typed in but is then deleted, the inputbox returns to its normal size and the button is hidden?? I have tried a few methods and I can hide the button, but the inputbox keeps flickering between sizes

thanks in advance

Share this post


Link to post
Share on other sites
FireFox

Hi,

The main problem in your script is that you create an input instead of resizing the original one.

Here you go :

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

#region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Enter Password", 616, 133, 192, 124)
GUISetBkColor(0x000080)
$Label1 = GUICtrlCreateLabel("Enter Password", 8, 8, 598, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("", 8, 80, 593, 21)
$Button1 = GUICtrlCreateButton("Correct Password", 344, 64, 257, 49)
GUICtrlSetState($Button1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

Local $sPassword = "", $blCorrectPassword = False

While 1
    $sPassword = GUICtrlRead($Input1)

    If $sPassword = "password" Then
        If Not $blCorrectPassword Then
            GUICtrlSetPos($Input1, 8, 80, 313, 21)
            GUICtrlSetState($Button1, $GUI_SHOW)

            $blCorrectPassword = True
        EndIf
    ElseIf $sPassword = "" Then
        If $blCorrectPassword Then
            GUICtrlSetState($Button1, $GUI_HIDE)
            GUICtrlSetPos($Input1, 8, 80, 593, 21)

            $blCorrectPassword = False
        EndIf
    EndIf

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    Sleep(10)
WEnd

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Noviceatthis

Thanks for the very speedy reply

Share this post


Link to post
Share on other sites
Noviceatthis

oh and incidentally, thanks for introducing me to the GUICtrlSetPos function, very useful :)

Share this post


Link to post
Share on other sites
FireFox

You're welcome :)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
spudw2k

If you are up for learning new things, I highly recommend looking at the _Crypt funcs in the help file. There is a simple, elegant example for a calculated hash / password mechanism (Much more secure than embedding a cleartext password).

  • Like 1

Share this post


Link to post
Share on other sites
Noviceatthis

spudw2k

thanks for that, looks complicated, gonna need to get my head round it :P

Share this post


Link to post
Share on other sites
spudw2k

Let me lend a little perspective. Hopefully you are familiar with what a hash is, but if you are not (which is fine) here is a quick explanation, otherwise skip ahead.

A hash is a calculated value for a given input data. It is a one-way operation that converts data into unique values that is intended to be difficult to reverse. There are many hashing algorithms some stronger (more resistant to attacks) and/or more popular than others.

Anyways, in the example script I lead you to there a few simple to understand tasks.

The _Crypt_HashData function was used first to generate the hash value for the password (in this case the password used was, "

Yellow fruit that is popular among monkeys"). The resulting hash value was defined in the script as $bPasswordHash="0xCE950A8D7D367B5CE038E636893B49DC".

Next a simple inputbox asks for the password (which is what your script does too).

It then compares the calculated hash of the data in the inputbox and compares it to the hash value of the $bPasswordHash value

You know the rest of the logic.

The reason embedding a hash is more secure is because it takes the exact specific data to create the same hash value. Also, any source code can be fairly easily retrieved from "complied" scripts. If a hacker looks at your source it is safer for them to obtain a hash versus the password itself. The only caution is if the password is forgotten there is no easy recovery beyond modifying the script and inserting a new password hash value.

I hope that makes some sense. Play around with the example a bit. Notice how even minimal changes cause the hash to be different (changing upper and lower case letters, adding or subtracting chars).

Edited by spudw2k

Share this post


Link to post
Share on other sites
Noviceatthis

spudw2k

Thank you so much for the explanation

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Enter Password", 616, 133, 192, 124)
GUISetBkColor(0x000080)
$Label1 = GUICtrlCreateLabel("Enter Password", 8, 8, 598, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("", 8, 80, 593, 21)
$Button1 = GUICtrlCreateButton("Correct Password", 344, 64, 257, 49)
GUICtrlSetState($Button1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$v = 0

$passwordhash = "0x5F4DCC3B5AA765D61D8327DEB882CF99"

While 1
$Answer = GUICtrlRead($Input1)
If _Crypt_HashData($Answer,$CALG_MD5) = $passwordhash Then
If $v <> 0 Then
Sleep(20)
Else
func1()
EndIf
Else
if $v <> 0 Then
GUICtrlSetState($Button1, $GUI_HIDE)
GUICtrlSetPos($Input1, 8, 80, 593, 21)
$v = 0
Else
Sleep(20)
EndIf
EndIf



$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button1
MsgBox(0, "", "It worked")
Exit

EndSwitch
WEnd


Func func1()
If _Crypt_HashData($Answer,$CALG_MD5) = $passwordhash Then
GUICtrlSetPos($Input1, 8, 80, 313, 21)
GUICtrlSetState($Button1, $GUI_SHOW)
$v = 2
EndIf
EndFunc ;==>func1

if you're interested, there is my old script with the use of hash.

I only have one final question, in the process of reading about this, I found multiple encryption functions like MD2, 4 and 5 and SHA1, what is the difference between these??

very many thanks

Edited by Noviceatthis

Share this post


Link to post
Share on other sites
spudw2k

Glad you are interested.

MD (aka Message DIgest) is a hashing standard and the numbers that follow (2,4,5) are the version revisions. The differences between them has to do with the encryption processes the strength of it. MD5 was the standard for quite sometime and is still used widely, but it has become less reliable due to collision attacks and other discovered vulerabilities. SHA (Secure Hash Algorithm) is another hashing algo that followed MD5 and is less susseptible to attacks, but still not invulnerable. There are also more verisons of SHA which produce larger digests including SHA-256 and SHA-512. For most intents and purposes MD5 and SHA1 hashes are fairly secure; particularly if you "salt the hash."

Edited by spudw2k

Share this post


Link to post
Share on other sites
Noviceatthis

Ah I see, and presumably the older MD's only still exist for older versions of windows, well thank you so much for everything spudw2k you've been a great help :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.