Jump to content

Password Saver (Secure!)


ludocus
 Share

Recommended Posts

Hi!

I use different passwords and usernames for a bunch of stuff.

Sometimes I go to a website and then forget what the password or username was ;).

So I made this. It's a simple but neat program that saves your username and password under a title.

Note:

-There's no login button, the script just goes on when the input contains the correct password. (a login button isn't necessary in my opinion)

-This program stores all usernames and passwords (encrypted though) in: @AppDataDir&'\userlist.txt'

-It stores all questions and answers in @AppDataDir&'\questionlist.txt'

-When you forgot your password and make a mistake filling out the fields, you can't use the program for an hour.

Here it is:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Ludocus

 Script Function:
    Password saver

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <String.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <Array.au3>
$_Passwords = ''
$_Usernames = ''
$_Titles = ''
$_Userlist = @AppDataDir&'\userlist.txt'
$_Questionlist = @AppDataDir&'\Questionlist.txt'
$_Banfile = @TempDir&'\Banfile.txt'
if FileExists($_Banfile) Then
    $_Splitz = StringSplit(FileRead($_Banfile), ' ', 1)
    if $_Splitz[1] = @YDAY Then
        if $_Splitz[2] > @HOUR then
            Exit
        EndIf
    EndIf
EndIf
global $_RandomQuestions[5] = ['A cat, a piano or a dolphin?', 'How long is your private jet?', '((400-98+291)/2)*8.5 = ?', 'Are you taking over the world right now?', 'A duck, a hawk and a bear. Pick the odd one out'] 
if not FileExists($_Userlist) or not FileExists($_Questionlist) Then
    $_FirstSteps = GUICreate("Password Saver, first steps", 315, 396, 193, 125)
    $_Label1 = GUICtrlCreateLabel("Welcome to Password Saver", 80, 8, 141, 17)
    $_PassInput3 = GUICtrlCreateInput("", 88, 64, 121, 21)
    $_Label2 = GUICtrlCreateLabel("Please enter a password:", 88, 40, 123, 17, $ES_PASSWORD)
    $_Label3 = GUICtrlCreateLabel("These are some questions for when you forget you password:", 16, 104, 293, 17)
    $_Label4 = GUICtrlCreateLabel("1:", 70, 142, 13, 17)
    $_Question1Input = GUICtrlCreateInput("Question 1", 88, 128, 121, 21)
    $_Answer1Input = GUICtrlCreateInput("Answer 1", 88, 152, 121, 21)
    $_Label5 = GUICtrlCreateLabel("2:", 70, 198, 13, 17)
    $_Question2Input = GUICtrlCreateInput("Question 2", 88, 184, 121, 21)
    $_Answer2Input = GUICtrlCreateInput("Answer 2", 88, 208, 121, 21)
    $_Label6 = GUICtrlCreateLabel("3:", 70, 254, 13, 17)
    $_Question3Input = GUICtrlCreateInput("Question 3", 88, 240, 121, 21)
    $_Answer3Input = GUICtrlCreateInput("Answer 3", 88, 264, 121, 21)
    $_Label7 = GUICtrlCreateLabel("When you forget your password you will be asked 3 fake questions and one of the three you just filled out, when you are asked a fake one, just enter nothing. When it is a question you just filled out, answer it.", 16, 304, 271, 55)
    $_SaveBut = GUICtrlCreateButton("Save", 120, 368, 75, 25, 0)
    GUISetState(@SW_SHOW)
    
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $_SaveBut
            $_Password1 = GUICtrlRead($_PassInput3)
            $_Question1 = GUICtrlRead($_Question1Input)
            $_Answer1 = GUICtrlRead($_Answer1Input)
            $_Question2 = GUICtrlRead($_Question2Input)
            $_Answer2 = GUICtrlRead($_Answer2Input)
            $_Question3 = GUICtrlRead($_Question3Input)
            $_Answer3 = GUICtrlRead($_Answer3Input)
            if $_Password1 <> '' and $_Question1 <> '' and $_Answer1 <> '' and $_Question2 <> '' and $_Answer2 <> '' and $_Question3 <> '' and $_Answer3 <> '' Then
                FileWrite($_Userlist, _StringEncrypt(1, $_Password1, 'secrez'))
                FileWrite($_Questionlist, _StringEncrypt(1, $_Question1, 'quisz')&' <-=-> '&_StringEncrypt(1, $_Answer1, 'quisz')&@CRLF&_StringEncrypt(1, $_Question2, 'quisz')&' <-=-> '&_StringEncrypt(1, $_Answer2, 'quisz')&@CRLF&_StringEncrypt(1, $_Question3, 'quisz')&' <-=-> '&_StringEncrypt(1, $_Answer3, 'quisz'))
                msgbox(32, 'Succes', 'Data saved!')
                GUIDelete($_FirstSteps)
                ExitLoop
            Else
                msgbox(16, 'Fail', 'Please fill out every field')
            EndIf
    EndSwitch
WEnd

Else
    $_Password1 = _StringEncrypt(0, FileReadLine($_Userlist, 1), 'secrez')
EndIf

$_Width1 = 170
$_Height1 = 80
$_PasswordGUI = GUICreate("Pass Save", $_Width1, $_Height1, _Mid($_Width1), _Mid('', $_Height1))
$_PassLabel1 = GUICtrlCreateLabel("Please enter password:", 24, 8, 114, 17)
$_PassInput1 = GUICtrlCreateInput("", 24, 30, 121, 21, $ES_PASSWORD)
$_ForgotBut = GUICtrlCreateButton('I forgot', 60, 55, 50, 25)
GUISetState(@SW_SHOW)

While 1
    if GUICtrlRead($_PassInput1) = $_Password1 then
        GUIDelete($_PasswordGUI)
        exitloop
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $_ForgotBut
            GUIDelete($_PasswordGUI)
            _ForgotPass()
    EndSwitch
    sleep(50)
WEnd

$_Width2 = 320
$_Height2 = 175
$_MainGUI = GUICreate("Password Saver", $_Width2, $_Height2, _Mid($_Width2), _Mid('', $_Height2))
$_List = GUICtrlCreateList("", 0, 0, 140, 180)
$_TitleLabel = GUICtrlCreateLabel("Title:", 155, 5, 55, 17)
$_TitleInput = GUICtrlCreateInput("", 155, 22, 150, 21)
$_UsernameLabel = GUICtrlCreateLabel("Username:", 155, 48, 55, 17)
$_UsernameInput = GUICtrlCreateInput("", 155, 65, 150, 21)
$_PassLabel2 = GUICtrlCreateLabel("Password:", 155, 95, 53, 17)
$_PassInput2 = GUICtrlCreateInput("", 155, 112, 150, 21)
$_AddChangeBut = GUICtrlCreateButton('Add', 140, 142, 45, 23)
$_NewBut = GUICtrlCreateButton('New', 185, 142, 45, 23)
GUICtrlSetState(-1, $GUI_DISABLE)
$_CopyBut = GUICtrlCreateButton('Copy', 230, 142, 45, 23)
GUICtrlSetState(-1, $GUI_DISABLE)
$_DelBut = GUICtrlCreateButton('Del', 275, 142, 45, 23)
GUICtrlSetState(-1, $GUI_DISABLE)
_LoadList()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $_List
            $_ReadList = GUICtrlRead($_List)
            if $_ReadList <> '' Then
                $_Curnum = _ArraySearch($_Titles, $_ReadList)
                GUICtrlSetData($_AddChangeBut, 'Change')
                GUICtrlSetState($_NewBut, $GUI_ENABLE)
                GUICtrlSetState($_CopyBut, $GUI_ENABLE)
                GUICtrlSetState($_DelBut, $GUI_ENABLE)
                GUICtrlSetData($_TitleInput, $_ReadList)
                GUICtrlSetData($_UsernameInput, $_Usernames[$_Curnum])
                GUICtrlSetData($_PassInput2, $_Passwords[$_Curnum])
            EndIf
            
        Case $_AddChangeBut
            if GUICtrlRead($_AddChangeBut) = 'Add' Then
                $_Username = GUICtrlRead($_UsernameInput)
                $_Password = GUICtrlRead($_PassInput2)
                $_Title = GUICtrlRead($_TitleInput)
                if $_Username = '' or $_Password = '' or $_Title = '' Then
                    msgbox(16, 'Fail', 'Please enter a username and a password')
                Else
                    $_Username = _StringEncrypt(1, $_Username, 'secrez1')
                    $_Password = _StringEncrypt(1, $_Password, 'secrez2')
                    $_Split = StringSplit(FileRead($_Userlist), @CRLF, 1)
                    if $_Split[$_Split[0]] = '' Then
                        FileWrite($_Userlist, $_Title&' <-=-> '&$_Username&' <-=-> '&$_Password)
                    Else
                        FileWrite($_Userlist, @CRLF&$_Title&' <-=-> '&$_Username&' <-=-> '&$_Password)
                    EndIf
                EndIf
                _LoadList()
            Else
                $_Username = GUICtrlRead($_UsernameInput)
                $_Password = GUICtrlRead($_PassInput2)
                $_Title = GUICtrlRead($_TitleInput)
                if $_Username = '' or $_Password = '' or $_Title = '' Then
                    msgbox(16, 'Fail', 'Please enter a username and a password')
                Else
                    $_Usernamez = _StringEncrypt(1, $_Username, 'secrez1')
                    $_Passwordz = _StringEncrypt(1, $_Password, 'secrez2')
                    _FileWriteToLine($_Userlist, $_Curnum+1, $_Title&' <-=-> '&$_Usernamez&' <-=-> '&$_Passwordz, 1)
                    _LoadList()
                    GUICtrlSetData($_UsernameInput, $_Username)
                    GUICtrlSetData($_PassInput2, $_Password)
                    GUICtrlSetData($_TitleInput, $_Title)
                EndIf
            EndIf
        
        Case $_NewBut
            GUICtrlSetState($_NewBut, $GUI_DISABLE)
            GUICtrlSetState($_CopyBut, $GUI_DISABLE)
            GUICtrlSetState($_DelBut, $GUI_DISABLE)
            GUICtrlSetData($_AddChangeBut, 'Add')
            GUICtrlSetData($_UsernameInput, '')
            GUICtrlSetData($_PassInput2, '')
            GUICtrlSetData($_TitleInput, '')
            
        Case $_CopyBut
            If ClipPut('Title: '&GUICtrlRead($_TitleInput)&@CRLF&'Username: '&GUICtrlRead($_UsernameInput)&@CRLF&'Password: '&GUICtrlRead($_PassInput2)&@CRLF&@CRLF&'Password Saver © Ludocus') Then
                msgbox(32, 'Information copied', 'Your information has been copied to the clipboard'&@CRLF&@CRLF&'Press CTRL+V somewhere to view it')
            Else
                msgbox(16, 'Error', 'Something went wrong.'&@CRLF&'The information is not copied to your clipboard')
            EndIf
            
        Case $_DelBut
            $_Split2 = StringSplit(FileRead($_Userlist), @CRLF, 1)
            $_NewText = $_Split2[1]
            For $i = 2 to $_Split2[0]
                If $i <> ($_Curnum+1) then $_NewText &= @CRLF&$_Split2[$i]
            Next
            FileDelete($_Userlist)
            FileWrite($_Userlist, $_NewText)
            GUICtrlSetState($_NewBut, $GUI_DISABLE)
            GUICtrlSetState($_CopyBut, $GUI_DISABLE)
            GUICtrlSetState($_DelBut, $GUI_DISABLE)
            GUICtrlSetData($_AddChangeBut, 'Add')
            GUICtrlSetData($_UsernameInput, '')
            GUICtrlSetData($_PassInput2, '')
            GUICtrlSetData($_TitleInput, '')
            _LoadList()
    EndSwitch
WEnd

Func _ForgotPass()
    if not FileExists($_Questionlist) then return 0
    $_Split1 = StringSplit(FileRead($_Questionlist), @CRLF, 1)
    $_Split3 = StringSplit($_Split1[Random(1, 3, 1)], ' <-=-> ', 1)
    $_Quest = _StringEncrypt(0, $_Split3[1], 'quisz')
    $_Answ = _StringEncrypt(0, $_Split3[2], 'quisz')
    $_Ran = Random(0, 4, 1)
    Do
        $_Ran2 = Random(0, 4, 1)
    Until $_Ran2 <> $_Ran
    global $_Quests[3] = [$_Quest, $_RandomQuestions[$_Ran], $_RandomQuestions[$_Ran2]]
    $_R = Random(0, 2, 1)
    Do
        $_R2 = Random(0, 2, 1)
    Until $_R2 <> $_R
    Do
        $_R3 = Random(0, 2, 1)
    Until $_R3 <> $_R and $_R3 <> $_R2
    $_Succes = 0
    $GUI = GUICreate("Password Saver", 322, 319, 193, 125)
    $_Label1 = GUICtrlCreateLabel("Please fill out all fields.", 104, 8, 109, 17)
    if $_Quests[$_R] = $_Quest then $_Real = 1
    $_Label2 = GUICtrlCreateLabel($_Quests[$_R], 16, 40, 292, 17)
    $_Quest1Input = GUICtrlCreateInput("", 16, 64, 121, 21)
    if $_Quests[$_R2] = $_Quest then $_Real = 2
    $_Label3 = GUICtrlCreateLabel($_Quests[$_R2], 16, 104, 292, 17)
    $_Quest2Input = GUICtrlCreateInput("", 16, 128, 121, 21)
    if $_Quests[$_R3] = $_Quest then $_Real = 3
    $_Label4 = GUICtrlCreateLabel($_Quests[$_R3], 16, 160, 292, 17)
    $_Quest3Input = GUICtrlCreateInput("", 16, 184, 121, 21)
    $_Label5 = GUICtrlCreateLabel("Please enter a new password:", 16, 224, 292, 17)
    $_NewPassInput = GUICtrlCreateInput("", 16, 248, 121, 21)
    $_ResetBut = GUICtrlCreateButton("Reset", 120, 288, 75, 25, 0)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                
            Case $_ResetBut
                If GUICtrlRead(Execute('$_Quest'&$_Real&'Input')) = $_Answ Then
                    if $_Real = 1 Then
                        if GUICtrlRead($_Quest2Input) = '' and GUICtrlRead($_Quest3Input) = '' Then
                            $_Succes = 1
                        Else
                            $_Succes = -1
                        EndIf
                    ElseIf $_Real = 2 Then
                        if GUICtrlRead($_Quest1Input) = '' and GUICtrlRead($_Quest3Input) = '' Then
                            $_Succes = 1
                        Else
                            $_Succes = -1
                        EndIf
                    ElseIf $_Real = 3 Then
                        if GUICtrlRead($_Quest1Input) = '' and GUICtrlRead($_Quest2Input) = '' Then
                            $_Succes = 1
                        Else
                            $_Succes = -1
                        EndIf
                    EndIf
                Else
                    $_Succes = -1
                EndIf
        EndSwitch
        If $_Succes = 1 Then
            $_Password1 = GUICtrlRead($_NewPassInput)
            _FileWriteToLine($_Userlist, 1, _StringEncrypt(1, $_Password1, 'secrez'), 1)
            msgbox(32, 'Succes', 'Your password has been reset!')
            GUIDelete($GUI)
            ExitLoop
        ElseIf $_Succes = -1 Then
            FileWrite($_Banfile, @YDAY&' '&@HOUR+1)
            msgbox(16, 'Fail', 'For security reasons you are not allowed to use this program for 1 hour.')
            exit
        EndIf
    WEnd
EndFunc

Func _LoadList()
    _GUICtrlListBox_ResetContent($_List)
    $_Text = StringSplit(FileRead($_Userlist), @CRLF, 1)
    if $_Text[0] = 1 then return ''
    global $_Passwords[$_Text[0]]
    global $_Usernames[$_Text[0]]
    global $_Titles[$_Text[0]]
    For $i = 2 to $_Text[0]
        if $_Text[$i] = '' then return 0
        $_String = StringSplit($_Text[$i], ' <-=-> ', 1)
        _GUICtrlListBox_AddString($_List, $_String[1])
        $_Titles[$i-1] = $_String[1]
        $_Usernames[$i-1] = _StringEncrypt(0, $_String[2], 'secrez1')
        $_Passwords[$i-1] = _StringEncrypt(0, $_String[3], 'secrez2')
    Next
EndFunc

Func _Mid($sWidth='', $sHeight='')
    If $sWidth <> '' and $sHeight <> '' Then
        local $sMid[2] = [(@DesktopWidth/2)-($sWidth/2), (@DesktopHeight/2)-($sHeight/2)]
        return $sMid
    ElseIf $sWidth <> '' Then
        return (@DesktopWidth/2)-($sWidth/2)
    Else
        return (@DesktopHeight/2)-($sHeight/2)
    EndIf
EndFunc

Enjoy! :)

Please comment

Edited by ludocus
Link to comment
Share on other sites

-This program stores all usernames and passwords (encrypted though) in: @AppDataDir&'\userlist.txt'

1. If someone will find my file "userlist.txt" and will look inside - he sees my master password to Password Saver in plain text ;)

2. When I click on existing item the button "Add" changes to "Change" - it's smart, but after changing, if I want to add new item I have to relaunch the script.

monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work.

Link to comment
Share on other sites

It's much better now ;)

I'm thinking about reminding procedure in case if the user forgets master password.

Maybe during first use (If Not FileExist @AppDataDir & '\userlist.txt') we should make few additional testing questions e.g.:

1. your birthday date

2. your mum's name

3. your city name

4. your favourite writer... etc.

These questions should be mixed with other "fake" questions (not appeared during test)

If anybody would answer on fake question - the program would be blocked for few hours.

And after this time - another set of fake questions and one true (of course answer should be the same as during first use/setup).

-------------

Make another small fix - after adding first item buttons "New", "Copy", "Del" are still disabled.

Maybe it would be better to organize buttons like: "New" (always enabled), "Edit", "Copy", "Del" (these 3 buttons disabled if none exists or none selected)

monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work.

Link to comment
Share on other sites

Ok I did exactly what you said and it's a nice little extra secure thing.

Make another small fix - after adding first item buttons "New", "Copy", "Del" are still disabled.

Maybe it would be better to organize buttons like: "New" (always enabled), "Edit", "Copy", "Del" (these 3 buttons disabled if none exists or none selected)

Those are supposed to be disabled, because you haven't selected an item.
Link to comment
Share on other sites

I was going to try this but ended up looking at keepass instead...

Not sure if I'm going to use it though.

Only because of a suggestion I am about to make that I find extremely important to me

If someone could find a way to import passwords that have already been saved by windows.

I have a number of saved passwords but don't remember all the sites, passwords, or even all the usernames I signed up with.

If a password utility can get these automatically and add them to the list then I would be one happy camper ;)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

It's much better now ;)

Q's & A's look pretty cool.

You could hide input passwords with asterisks by default and add the button "show/hide". It would be more safe (someone can stand behind you at that time) :)

monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work.

Link to comment
Share on other sites

I was going to try this but ended up looking at keepass instead...

Not sure if I'm going to use it though.

Only because of a suggestion I am about to make that I find extremely important to me

If someone could find a way to import passwords that have already been saved by windows.

I have a number of saved passwords but don't remember all the sites, passwords, or even all the usernames I signed up with.

If a password utility can get these automatically and add them to the list then I would be one happy camper ;)

kaotkbliss, take a look at Lastpass, I use it for all the logins I use on any browser. As far as I know, it can only import the passwords saved by IE and FF, but once they are imported, they're available for use. The site is extremely secure, it's so secure that even the site owners can't access your passwords or any of the information saved on it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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