Sign in to follow this  
Followers 0
RichE

Secure Address Book

2 posts in this topic

I've been working on this little project for about the last week, and thought that I'd share it, for feedback and better coding solutions,

somethings are not working, the search box (test code is still in there) and the blanking of the gui before adding a new contact and asking for confirmation on delete, but the code is beta atm.

anyway here's the code, and a compiled version below

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.10.0

Author: Richard Easton

Script Function:

Secure Address book

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

; Script Start - Add your code below here

FileInstall("Prev.ico", @ScriptDir)

FileInstall("Next.ico", @ScriptDir)

$path = @ScriptDir

$inifile = $path & "\settings.ini"

#include <String.au3>

#include <File.au3>

#include <GUIConstants.au3>

$path = @ScriptDir

$inifile = $path & "\settings.ini"

Dim $first_login, $loginbtn

;check the ini file exists

If Not FileExists($inifile) Then

;first run create ini file and ask for username and password

MsgBox(64, "SecAdBook First run", "Please answer the following" & @LF & "questions so SecAdBook can setup" & @LF & "correctly and securely.")

$username = InputBox("Username.", "Please enter a username", "", "", 200, 90)

$password = InputBox("Password.", "Please enter a password", "", "*", 200, 90)

;encrypt username and password

If $username = "" Or $password = "" Then

MsgBox(48, "Warning!", "Username or Password Missing!" & @CR & "Please restart!", 3)

Exit

Else

$encrypted_username = _StringEncrypt(1, $username, "bob@1234!", 2)

$encrypted_password = _StringEncrypt(1, $password, "bob@1234!", 2)

;write encrypted username and password to ini file

IniWrite($inifile, "User details", "username", $encrypted_username)

IniWrite($inifile, "User details", "password", $encrypted_password)

MsgBox(64, "Login Details Stored", "Please Retsart SecAdbook", 5)

Exit

EndIf

Else

$SecAdBookLogin = GUICreate("SecAdBook Login", 215, 200, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST)

GUISetCursor(0)

GUISetBkColor(0xc0c0c0)

GUICtrlCreateLabel("Username", 8, 8, 71, 24)

GUICtrlSetFont(-1, 12, 400, 0, "Impact")

GUICtrlSetColor(-1, 0xFFFF00)

$uint = GUICtrlCreateInput("", 8, 32, 193, 21)

GUICtrlCreateLabel("Password", 8, 63, 68, 24)

GUICtrlSetFont(-1, 12, 400, 0, "Impact")

GUICtrlSetColor(-1, 0xFFFF00)

$pint = GUICtrlCreateInput("", 8, 88, 193, 21, $ES_PASSWORD)

$msglabel = GUICtrlCreateLabel("", 8, 120, 193, 25, $SS_CENTER)

$loginbtn = GUICtrlCreateButton("Login", 48, 140, 113, 25)

GUICtrlSetFont(-1, 12, 400, 0, "Impact")

GUICtrlSetBkColor(-1, 0xFF0000)

WinSetTrans($SecAdBookLogin, "", 0)

GUISetState(@SW_SHOW)

$t = 0

Do

WinSetTrans($SecAdBookLogin, "", $t)

$t = $t + 1

Until $t = 255

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $loginbtn

;get user to login

;read stored username and password

$stored_username = IniRead($inifile, "User details", "username", "")

$stored_password = IniRead($inifile, "User details", "password", "")

;decrypt stored username and password

$decrypted_username = _StringEncrypt(0, $stored_username, "bob@1234!", 2)

$decrypted_password = _StringEncrypt(0, $stored_password, "bob@1234!", 2)

;compare login username with stored username

$username = GUICtrlRead($uint)

$password = GUICtrlRead($pint)

If $username <> $decrypted_username Or $password <> $decrypted_password Then

GUICtrlSetData($msglabel, " Invalid Username or Password ", "")

GUICtrlSetColor($msglabel, 0xFF0000)

Sleep(2000)

GUICtrlSetData($msglabel, "", "")

GUICtrlSetData($uint, "", "")

GUICtrlSetData($pint, "", "")

Else

Opt("WinTitleMatchMode", 2) ; Match substring

GUICtrlSetData($msglabel, " Processing Login Details ", "")

GUICtrlSetColor($msglabel, 0x00FF00)

Sleep(1000)

GUICtrlSetData($msglabel, " Login Details Valid", "")

GUICtrlSetColor($msglabel, 0x00FF00)

Sleep(1000)

$t = 255

Do

WinSetTrans($SecAdBookLogin, "", $t)

$t = $t - 1

;sleep(1)

Until $t = 0

GUIDelete($SecAdBookLogin)

ExitLoop

EndIf

EndSwitch

WEnd

EndIf

$address_book = $path & "\Addbook.SAB"

;check address book exists

If Not FileExists($address_book) Then

MsgBox(64, "Address book", "Creating address book", 3)

FileWrite($address_book, "")

$enc_fn = _StringEncrypt(1, "John", $decrypted_password, 1)

$enc_sn = _StringEncrypt(1, "Doe", $decrypted_password, 1)

$enc_ad = _StringEncrypt(1, "1 anytown", $decrypted_password, 1)

$enc_pc = _StringEncrypt(1, "AB123CD", $decrypted_password, 1)

$enc_ph = _StringEncrypt(1, "0123456789", $decrypted_password, 1)

$enc_ea = _StringEncrypt(1, "Bob@Bob.com", $decrypted_password, 1)

;write entry

FileWriteLine($address_book, $enc_fn & "," & $enc_sn & "," & $enc_ad & "," & $enc_pc & "," & $enc_ph & "," & $enc_ea)

MsgBox(64, "Restart Required", "Please Restart SecAdBook", 3)

Exit

Else

Dim $decrypted_fn, $decrypted_sn, $decrypted_ad, $decrypted_pc, $decrypted_ph, $decrypted_ea

;count lines of address book

$no_of_contacts = _FileCountLines($address_book)

If $no_of_contacts = 0 Then

MsgBox(48, "Warning!", "No Contacts Found!", 3)

ElseIf $no_of_contacts > 0 Then

;read first line of address book

$array_read = FileReadLine($address_book, 1)

;split component parts of the contact details

$contact = StringSplit($array_read, ",")

;decrypt contact encrypted parts

$decrypted_fn = _StringEncrypt(0, $contact[1], $decrypted_password)

$decrypted_sn = _StringEncrypt(0, $contact[2], $decrypted_password)

$decrypted_ad = _StringEncrypt(0, $contact[3], $decrypted_password)

$decrypted_pc = _StringEncrypt(0, $contact[4], $decrypted_password)

$decrypted_ph = _StringEncrypt(0, $contact[5], $decrypted_password)

$decrypted_ea = _StringEncrypt(0, $contact[6], $decrypted_password)

EndIf

EndIf

;create gui after validation

#include <GUIConstants.au3>

#include <GUIConstantsEX.au3>

$SecAdBook = GUICreate("SecAdBook V", 520, 330, -1, -1, $WS_POPUP + $WS_BORDER)

GUISetCursor(0)

GUISetBkColor(0xc0c0c0)

GUICtrlCreateGroup("Contact Details", 8, 8, 297, 289)

GUICtrlCreateLabel("First Name", 16, 24, 54, 17)

$Firstname = GUICtrlCreateInput("", 16, 40, 121, 21)

GUICtrlSetData($Firstname, $decrypted_fn)

GUICtrlCreateLabel("Surname", 168, 24, 46, 17)

$Surname = GUICtrlCreateInput("", 168, 40, 121, 21)

GUICtrlSetData($Surname, $decrypted_sn)

GUICtrlCreateLabel("Address", 16, 64, 42, 17)

$address = GUICtrlCreateEdit("", 16, 80, 273, 89, $WS_VSCROLL + $WS_HSCROLL + $ES_WANTRETURN)

GUICtrlSetData($address, $decrypted_ad)

GUICtrlCreateLabel("Post Code", 16, 176, 53, 17)

$Postcode = GUICtrlCreateInput("", 16, 192, 121, 21)

GUICtrlSetData($Postcode, $decrypted_pc)

GUICtrlCreateLabel("Phone Number", 168, 176, 75, 17)

$PhoneNo = GUICtrlCreateInput("", 168, 192, 121, 21)

GUICtrlSetData($PhoneNo, $decrypted_ph)

GUICtrlCreateLabel("Email Address", 16, 216, 70, 17)

$Emailaddy = GUICtrlCreateInput("", 16, 232, 273, 21)

GUICtrlSetData($Emailaddy, $decrypted_ea)

GUICtrlCreateGroup("Search", 312, 8, 201, 73)

$Search_input = GUICtrlCreateInput("Search..?", 320, 24, 185, 21)

$Search_btn = GUICtrlCreateButton("Search", 320, 48, 185, 25, 0)

GUICtrlSetState($Search_input, @SW_DISABLE)

GUICtrlSetState($Search_btn, @SW_DISABLE)

GUICtrlCreateGroup("Controls", 312, 88, 201, 209)

$Add_new_btn = GUICtrlCreateButton("Add New Contact", 320, 104, 185, 25, 0)

$Delete_Current_Btn = GUICtrlCreateButton("Delete Current Contact", 320, 136, 187, 25, 0)

GUICtrlCreateLabel("Contact", 320, 175, 80, 25)

$current_record = GUICtrlCreateInput("1", 360, 170, 30, 20)

GUICtrlCreateLabel("of", 400, 175, 30, 25)

$max_record = GUICtrlCreateInput($no_of_contacts, 420, 170, 30, 20)

$prev = GUICtrlCreateIcon("prev.ico", -1, 320, 200, 16, 16)

$next = GUICtrlCreateIcon("next.ico", -1, 360, 200, 16, 16)

$Exit_btn = GUICtrlCreateButton("Exit", 320, 264, 185, 25, 0)

WinSetTrans($SecAdBook, "", 0)

GUISetState(@SW_SHOW)

$t = 0

Do

WinSetTrans($SecAdBook, "", $t)

$t = $t + 1

Until $t = 255

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

$t = 255

Do

WinSetTrans($SecAdBook, "", $t)

$t = $t - 1

Until $t = 0

Exit

Case $Exit_btn

$t = 255

Do

WinSetTrans($SecAdBook, "", $t)

$t = $t - 1

Until $t = 0

Exit

#cs

Case $Search_btn

$search = GUICtrlRead($Search_input)

if $search = "Search..?" or $search = "" Then

Msgbox(48, "Warning!", "No Search Criteria Entered!", 3)

else

$s = 1

$f = _FileCountLines($address_book)

Do

$array_read = FileReadLine($address_book, $s)

;split component parts of the contact details

$contact = StringSplit($array_read, ",")

;decrypt contact encrypted parts

For $i = 1 To 6

$decrypted_part = _StringEncrypt(0, $contact[$i], $decrypted_password)

$check = StringCompare($search, $decrypted_part, 2)

;MsgBox(64, "", $check)

If $check = 0 Then

Call("decrypt")

;update Gui

GUICtrlSetData($Firstname, $decrypted_fn, "")

GUICtrlSetData($Surname, $decrypted_sn, "")

GUICtrlSetData($address, $decrypted_ad, "")

GUICtrlSetData($Postcode, $decrypted_pc, "")

GUICtrlSetData($PhoneNo, $decrypted_ph, "")

GUICtrlSetData($Emailaddy, $decrypted_ea, "")

GUICtrlSetData($current_record, $s, "")

ExitLoop

EndIf

Next

$s = $s + 1

Until $s = $f

EndIf

#ce

Case $Delete_Current_Btn

$record = GUICtrlRead($current_record)

_FileWriteToLine($address_book, $record, "", 1)

MsgBox(48, "Record Deleted!", "Record No " & $record & " deleted", 3)

Case $Add_new_btn

;read contact entry

$fn = GUICtrlRead($Firstname)

$sn = GUICtrlRead($Surname)

$ad = GUICtrlRead($address)

$pc = GUICtrlRead($Postcode)

$ph = GUICtrlRead($PhoneNo)

$ea = GUICtrlRead($Emailaddy)

;encrypt details

$enc_fn = _StringEncrypt(1, $fn, $decrypted_password, 1)

$enc_sn = _StringEncrypt(1, $sn, $decrypted_password, 1)

$enc_ad = _StringEncrypt(1, $ad, $decrypted_password, 1)

$enc_pc = _StringEncrypt(1, $pc, $decrypted_password, 1)

$enc_ph = _StringEncrypt(1, $ph, $decrypted_password, 1)

$enc_ea = _StringEncrypt(1, $ea, $decrypted_password, 1)

;write entry

FileWriteLine($address_book, $enc_fn & "," & $enc_sn & "," & $enc_ad & "," & $enc_pc & "," & $enc_ph & "," & $enc_ea)

MsgBox(64, "New Contact Added", "file write successful", 3)

Case $prev

$current = GUICtrlRead($current_record)

If $current = 1 Then

MsgBox(48, "Address Book", "You are at the start of the address book", 3)

Else

$record = GUICtrlRead($current_record) - 1

$array_read = FileReadLine($address_book, $record)

;call decrypt function

Call("decrypt")

;update Gui

GUICtrlSetData($Firstname, $decrypted_fn, "")

GUICtrlSetData($Surname, $decrypted_sn, "")

GUICtrlSetData($address, $decrypted_ad, "")

GUICtrlSetData($Postcode, $decrypted_pc, "")

GUICtrlSetData($PhoneNo, $decrypted_ph, "")

GUICtrlSetData($Emailaddy, $decrypted_ea, "")

GUICtrlSetData($current_record, $record, "")

EndIf

Case $next

$current = GUICtrlRead($current_record)

$max = GUICtrlRead($max_record)

If $current = $max Then

MsgBox(48, "Address Book", "You are at the end of the address book", 3)

Else

$record = GUICtrlRead($current_record) + 1

$array_read = FileReadLine($address_book, $record)

;call decrypt function

Call("decrypt")

;update gui

GUICtrlSetData($Firstname, $decrypted_fn, "")

GUICtrlSetData($Surname, $decrypted_sn, "")

GUICtrlSetData($address, $decrypted_ad, "")

GUICtrlSetData($Postcode, $decrypted_pc, "")

GUICtrlSetData($PhoneNo, $decrypted_ph, "")

GUICtrlSetData($Emailaddy, $decrypted_ea, "")

GUICtrlSetData($current_record, $record, "")

EndIf

EndSwitch

WEnd

Func decrypt()

;split component parts of the contact details

$contact = StringSplit($array_read, ",")

;decrypt contact encrypted parts

$decrypted_fn = _StringEncrypt(0, $contact[1], $decrypted_password)

$decrypted_sn = _StringEncrypt(0, $contact[2], $decrypted_password)

$decrypted_ad = _StringEncrypt(0, $contact[3], $decrypted_password)

$decrypted_pc = _StringEncrypt(0, $contact[4], $decrypted_password)

$decrypted_ph = _StringEncrypt(0, $contact[5], $decrypted_password)

$decrypted_ea = _StringEncrypt(0, $contact[6], $decrypted_password)

EndFunc ;==>decrypt

Secure_address_book.rar


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites



A little suggestions for the input box's, use:

If @error Then Exit

After each one, this meant that they closed the inputbox's with cancel or the X. :)

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