Simple Password Keeper

You can post your code snippets here for others to use and learn from
Post Reply
User avatar
Redlion
Posts: 73
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Simple Password Keeper

Post by Redlion » Wed Apr 15, 2015 2:16 pm

Hi Everyone,

As I was the one to ask for this section, let me start it off.

I am certainly not the best coder by any means and I do not beleive that there is only one way to do things, this is just my take on it.

Here is a quick and simple password keeper. It does not have a lot of security except the password to get into the program. The password is inbedded in the program so once compiled will be very difficult to workout.
In this example the Password is "Amiga".

Code: Select all

@VERSION 6,0
@REQUIRE "MUIRoyale"
@APPTITLE "Keeper"
@APPVERSION "$VER: 1.0.0 (01.03.15)"
@APPCOPYRIGHT "©2015, George Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Login and Password Storage Program"

@DISPLAY {Hidden = True}

mui.CreateGui([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="KEPR">
    <window title="Keeper - Login and Password Storage Program" id="window" width="500" open="false" notify="closerequest" >
        <vgroup background="pre_ShadowFill">
             <vgroup>
                <colgroup columns="1" frame="group">
                    <listview Id="Found">
                        <column Title="Application">
                        </column>
                        <column Title="UserName">
                        </column>
                        <column Title="Password">
                        </column>
                    </listview>
                </colgroup>
                <colgroup columns="4" frame="group">
                    <button id="Add"    weight="25" notify="pressed">ADD</button>
                    <button id="Edit"   weight="25" notify="pressed">EDIT</button>
                    <button id="Remove" weight="25" notify="pressed">DELETE</button>
                    <button id="Quit"   weight="25" notify="pressed">QUIT</button>
                </colgroup>   
            </vgroup>
        </vgroup>
    </window>
    <window title="Add New Application" width="500" muiid="NewA" id="wi_NewA" notify="closerequest" open="false">
        <vgroup>
            <colgroup columns="1" frame="group">
            <hgroup>
                <vgroup>
                    <label> Application </label>
                    <label> Login </label>
                    <label> Password </label>
                </vgroup>
                <vgroup>
                    <string id="NewApp"  Contents=""/>
                    <string id="NewLog"  Contents=""/>
                    <string id="NewPass" Contents=""/>
                </vgroup>
            </hgroup>    
            <hgroup>
                <button id="NewSave" notify="Pressed"> _Save </button>
                <rectangle/>
                <button id="NewCancel" notify="Pressed"> _Cancel </button>
            </hgroup>
            </colgroup>
        </vgroup>
    </window>
    <window title="Edit New Application" width="500" muiid="EdtA" id="wi_EdtA" notify="closerequest" open="false">
        <vgroup>
            <colgroup columns="1" frame="group">
            <hgroup>
                <vgroup>
                    <label> Application </label>
                    <label> Login </label>
                    <label> Password </label>
                </vgroup>
                <vgroup>
                    <string id="EdApp"  Contents=""/>
                    <string id="EdLog"  Contents=""/>
                    <string id="EdPass" Contents=""/>
                </vgroup>
            </hgroup>    
            <hgroup>
                <button id="EditSave" notify="Pressed"> _Save </button>
                <rectangle/>
                <button id="EditCancel" notify="Pressed"> _Cancel </button>
            </hgroup>
            </colgroup>
        </vgroup>
    </window>
</application>
]])

Function RemoveDetails() ; **********************************************************************************
    Pick = mui.get("Found","Active")
    Applic$ = mui.DoMethod("Found","GetEntry",Pick)
    Result = systemrequest(" DELETE DETAILS ! ","You are about to DELETE "..Applic$,"CONTINUE|CANCEL",#REQICON_WARNING)
    Switch Result
        Case 1
            Pick = mui.get("Found","Active")
            mui.DoMethod("Found","Remove",Pick)
            WriteNewFile()

    EndSwitch
EndFunction

Function AddDetails() ; *************************************************************************************
  mui.Set("wi_NewA", "open", true)

EndFunction

Function EditDetails() ; ************************************************************************************
    mui.Set("wi_EdtA", "open", true)
    Pick = mui.get("Found","Active")
    LA$,LL$,LP$ = mui.DoMethod("Found","GetEntry",Pick)
    mui.set("EdApp","contents",LA$)
    mui.set("EdLog","contents",LL$)
    mui.set("EdPass","contents",LP$)
    
EndFunction

Function WriteNewFile() ; ***********************************************************************************
    DeleteFile(Dir$.."/keeper.dat")
    NOE = mui.get("Found","Entries")
    OpenFile(1,Dir$.."/keeper.dat",#MODE_WRITE)
    For C = 0 to NOE -1
        LA$,LL$,LP$ = mui.DoMethod("Found","GetEntry",c)
        BLA$ = Base64Str(LA$,False)
        BLL$ = Base64Str(LL$,False)
        BLP$ = Base64Str(LP$,False)
        WriteLine(1,BLA$)
        WriteLine(1,BLL$)
        WriteLine(1,BLP$)
    Next 
    CloseFile(1)

EndFunction

Function p_EventFunc(msg) ; EVENT HANDLER ===================================================================
    Switch msg.action
        Case "MUIRoyale"

            Switch msg.attribute
        
                Case "CloseRequest"
                     Switch msg.id
                        case "wi_NewA" 
                            mui.Set("wi_NewA","open",False)
                                                
                        case "window"
                            End

                    EndSwitch

                Case "Pressed":
                    p_MUIEvent(msg.id)

            EndSwitch

        Case "HideWindow"
            mui.Set("app", "iconified", True)

        Case "ShowWindow"
            mui.Set("app", "iconified", False)

     EndSwitch
EndFunction

Function p_MUIEvent(id) ; MUI EVENTS ========================================================================
  Switch id
    Case "Add"
        AddDetails()
     
    Case "Edit"
        EditDetails()

    Case "Remove"
        RemoveDetails()

    Case "NewSave"
        NA$ = mui.get("NewApp","Contents")
        NL$ = mui.get("NewLog","Contents")
        NP$ = mui.get("NewPass","Contents")
        mui.DoMethod("Found","Insert","Bottom",NA$,NL$,NP$)
        mui.Set("wi_NewA","open",False)
        WriteNewFile()

    Case "NewCancel"
        mui.Set("wi_NewA","open",False)

    Case "EditSave"
        NA$ = mui.get("EdApp","Contents")
        NL$ = mui.get("EdLog","Contents")
        NP$ = mui.get("EdPass","Contents")
        mui.DoMethod("Found","Rename","Active",NA$,NL$,NP$)
        mui.Set("wi_EdtA","open",False)
        WriteNewFile()

    Case "EditCancel"
        mui.Set("wi_EdtA","open",False)

    Case "Quit"
      End

  EndSwitch
EndFunction

; listen to these events!
InstallEventHandler({MUIRoyale = p_EventFunc, HideWindow = p_EventFunc, ShowWindow = p_EventFunc})

Dir$= getcurrentdirectory()

PWC$ = MD5str("Amiga")
Password$,OK = StringRequest(" KEEPER ","Enter Keeper Password.","",#All,8,True)
if Password$ <> ""
   PWE$ = MD5str(Password$)
   if PWE$ = PWC$
       openfile(1,Dir$.."/keeper.dat")
           while EOF(1) = False 
                LA$ = readline(1)
                LL$ = readline(1)
                LP$ = readline(1)
                BLA$ = Base64Str(LA$,true)
                BLL$ = Base64Str(LL$,true)
                BLP$ = Base64Str(LP$,true)
                mui.DoMethod("Found", "Insert", "Bottom",BLA$,BLL$,BLP$)
           wend
       closefile(1)
       mui.Set("window","Open",True) 
    Else
        End
    endif  
else
  End
endif
; main loop!
Repeat
     WaitEvent
Forever 
To make the program more secure, data could be encripted before it is saved and decripted once it load in.

Hope it is useful to someone and I hope this section becomes full of short example code to compliment the documentation and help people learn more Hollywood coding techniques.

If you think that you have made some improvements ( or fix a bug ) to this code please post them so other can benefit as well.

Enjoy, Leo

PS. more to come.
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32

Post Reply