Password manager for iPhone2 and up (modified)

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Password manager for iPhone2 and up (modified)

Post by Henko »

With this app you can safely keep your userid's and passwords on your phone.
Together with short identifiers those data are kept in an encrypted file. They are decrypted only when the program is running and records can be added, deleted or modified then.

When first used (or when the datafile has been deleted), the program will asked to enter a encryption key, which must be used each time when the program is started. Do not forget this key, because no one or nothing can help you to revive the encrypted data. The maximum permitted length of the key is 15 caracters.

After entering the correct key, the records become accessable. The short identifiers are shown in a scrollable list. If a identifier is selected in the list, the record with identifier, userid, and password are shown in 3 fields. You can then modify these fields.
Modifying a userid or password has effect on the current record. Modifying the identifier has no effect on the current record, but is used to add a new record. If you want to modify the identifier of a record, the only way is to delete the record and reenter (add) it with the new identifier.

The identifiers in the list are kept in alphabetic order.
The encrypted file is refreshed immediately after each individual modification, addition, or deletion. There is no need for a save command at program exit. You can exit on any moment in either way. The name of the encrypted file is fixed on "x7cr13f" and resides in the directory where the program is placed.

An export function is provided to create a decrypted, ascci readable file. This file with name "account13f" in the same directory, may be printed to get a hard copy of your data which can be hidden in a proper place (f.i. in one of your 1000+ books). In this way, if you do forget the encryption key, you have at least your data (if you remember the correct book!).
If you forget to delete the decrypted file after printing, the program will delete it upon the next usage.

Do NOT use comma's in your data,as the comma is used as separator in the "split" function.

Code: Select all

init_app
dim ft$(3*maxrec),fe$(maxrec,3),index$(maxrec)
w_open ("Account vault",10,10,width-10,height-10)
if file_exists("account13f") then file "account13f" delete
if not file_exists("x7cr13f") then
  init_text ! key$=get_key1$(50) ! nrec=0
  else
  file "x7cr13f" input in$ ! key$=get_key2$(50)
  out$=crypt$(in$,key$,-1) ! split out$ to ft$,nel with ","
  for k=1 to nel ! i=floor((k-1)/3)+1 ! fe$(i,k-3*(i-1))=ft$(k) ! next k
  nrec=nel/3 ! for k=1 to nrec ! index$(k)=fe$(k,1) ! next k
  end if
init_disp ! if nrec then disp_rec(1)

loop1:
k=list_selected("ind")
if k>0 and k<>ksel and k<=nrec then
  ksel=k ! disp_rec(ksel)
  end if
if field_changed("usid") then
  fe$(ksel,2)=field_text$("usid") ! changed=1
  end if
if field_changed("pwrd") then
  fe$(ksel,3)=field_text$("pwrd") ! changed=1
  end if

if button_pressed("add") and nrec<maxrec then
  z$=field_text$("icod") ! changed=1
  for i=1 to nrec ! if z$>index$(i) then continue
    ksel=i ! goto lab1
    next i
  ksel=nrec+1
lab1:
  if ksel<=nrec then
    for k=nrec to ksel step-1
      index$(k+1)=index$(k)
      for j=1 to 3 ! fe$(k+1,j)=fe$(k,j) ! next j
      next k
    end if
  index$(ksel)=z$ ! fe$(ksel,1)=z$
  fe$(ksel,2)=field_text$("usid") ! fe$(ksel,3)=field_text$("pwrd")
  if fe$(ksel,2)="" then fe$(ksel,2)=" "
  if fe$(ksel,3)="" then fe$(ksel,3)=" "
  nrec+=1 ! build_list ! disp_rec(ksel)
  end if

if button_pressed("del") and nrec>0 then
  changed=1
  if nrec=1 or ksel=nrec then
    index$(nrec)="" ! nrec-=1
    else
    for i=ksel to nrec-1
      for j=1 to 3 ! fe$(i,j)=fe$(i+1,j) ! next j
      index$(i)=index$(i+1)
      next i
    index$(nrec)="" ! nrec-=1
    end if
  build_list
  if nrec then disp_rec(ksel) else init_fields
  end if

if changed and nrec>0 then
  changed=0 ! in$=""
  for i=1 to nrec ! for j=1 to 3
    in$ &= fe$(i,j) ! in$ &= ","
    next j ! next i
  out$=crypt$(in$,key$,1)
  file "x7cr13f" delete ! file "x7cr13f" print out$
  end if

if button_pressed("xpo") and nrec>0 then
  if file_exists("account13f") then file "account13f" delete
  for i=1 to nrec ! for j=1 to 3
    file "account13f" print fe$(i,j)
    next j ! file "account13f" print ! next i
  end if

if button_pressed("exi") then stop

goto loop1
end

def init_app
option base 1 ! changed=0 ! .maxrec=300
.width=320 ! .height=436
graphics ! graphics clear .8,.8,.8
fill color .8,.8,.8
draw font size 16
end def

def init_text
ys=160
draw text "Enter the (de-)cryption key" at 20,ys+40
draw text "to be used in this app." at 20,ys+60
draw text "Max.length is 15 tokens." at 20,ys+80
draw text "Preferable lengths are prime" at 20,ys+100
draw text "numbers such as 7 or 13." at 20,ys+120
draw text "This initial key must be" at 20,ys+140
draw text "used unchanged subsequently" at 20,ys+160
draw text "to be able to read your data." at 20,ys+180
draw text "Be sure not to forget your" at 20,ys+200
draw text "key, as no one or nothing can" at 20,ys+220
draw text "help you out!" at 20,ys+240
end def

def init_disp
fill rect 14,36 to .width-14,.height-14
draw color 0,0,1 ! draw size 2 ! draw rect 15,39 to 120,216
draw color 0,0,0 
build_list
button "add" title "Add" at 130,40 size 80,32
button "del" title "Del" at 220,40 size 80,32
button "xpo" title "Export" at 130,76 size 80,32
button "exi" title "Exit" at 220,76 size 80,32
field "icod" text "" at 130,120 size 120,28
field "usid" text "" at 130,154 size 170,28
field "pwrd" text "" at 130,188 size 170,28
end def

def init_fields
list "ind" text .index$ at 16,40 size 103,175
field "icod" set text ""
field "usid" set text ""
field "pwrd" set text ""
end def

def build_list
if .nrec then
  dim lind$(.nrec)
  for i=1 to .nrec ! lind$(i)=.index$(i) ! next i
  else 
  lind$(1)=""
  end if
list "ind" text lind$ at 16,40 size 103,175
end def

def get_key1$(ys)
loop:
field "k1" text "enter key here" at 60,ys size 200,30
loop1: if field_changed("k1") then k1$=field_text$("k1") else loop1
fill rect 20,ys+100 to .width-20,ys+120
field "k2" text "repeat key please" at 60,ys+50 size 200,30
loop2: if field_changed("k2") then k2$=field_text$("k2") else loop2
if k1$=k2$ and len(k1$)<16 then
  field "k1" delete ! field "k2" delete
  get_key1$=k1$ ! return
  else
  draw color .6,0,0
  draw text "keys not equal or too long!" at 20,ys+100
  draw color 0,0,0 ! goto loop
  end if
end def

def get_key2$(ys)
draw text "Enter the (de-)cryption key" at 20,ys
loop:
field "k1" text "enter key here" at 60,ys+30 size 200,30
loop1: if field_changed("k1") then k1$=field_text$("k1") else loop1
if len(k1$)<16 then
  field "k1" delete ! get_key2$=k1$ ! return
  else
  draw color .6,0,0 ! draw text "key is too long!" at 80,ys+70
  draw color 0,0,0 ! goto loop
  end if
end def

def disp_rec(ksel)
list "ind" set selection ksel
field "icod" set text .fe$(ksel,1)
field "usid" set text .fe$(ksel,2)
field "pwrd" set text .fe$(ksel,3)
end def

def w_open (title$,xtop,ytop,xbot,ybot)
r=10 ! draw color 0,0,0 ! draw size 4
draw circle xtop,ytop to xtop+20,ytop+20
draw circle xbot-20,ytop to xbot,ytop+20
draw circle xtop,ybot-20 to xtop+20,ybot
draw circle xbot-20,ybot-20 to xbot,ybot
draw line xtop+r,ytop to xbot-r,ytop
draw line xtop+r,ybot to xbot-r,ybot
draw line xtop,ytop+r to xtop,ybot-r
draw line xbot,ytop+r to xbot,ybot-r
fill rect xtop+r,ytop+2 to xbot-r,ybot-2
fill rect xtop+2,ytop+r to xbot-2,ybot-r
if title$<>"" then
  l=(xbot-xtop-10*len(title$))/2
  draw line xtop,ytop+24 to xbot,ytop+24
  draw color 0,0,1
  draw text title$ at xtop+l,ytop+4
  draw color 0,0,0
end if
end def

def crypt$(in$,key$,mode)
dim key(15)
lk=len(key$) ! lt=len(in$) ! out$=""
for i=1 to lk ! key(i)=asc(substr$(key$,i,i)) ! next i
for i=1 to lt
out$=out$ & chr$(asc(substr$(in$,i,i))+mode*key(1+mod(i,lk)))
next i
' file file_out$ print """" & out$ & """"
crypt$=out$
end def

def mod(a,m)
d=a/m ! mod=m*(d-floor(d))
end def
Last edited by Henko on Sun Feb 23, 2014 5:55 pm, edited 1 time in total.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Password manager for iPhone2 and up

Post by Mr. Kibernetik »

Looks like a great application!

On first run after entering pass and re-entering it, I get error of incorrect LIND$ dimension, because NREC = 0.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Password manager for iPhone2 and up

Post by Henko »

Shame on me! I did extensive testing (as usual), but the lind$ item was a last minute addition, not tested whith an empty file. I will take care immediately. Thanks

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Password manager for iPhone2 and up (modified)

Post by Henko »

One additional remark: if you fill or change one of the 3 inputfields, you have to press the <return> key to effectuate the input. It's the return key which triggers the "field_changed" function.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Password manager for iPhone2 and up (modified)

Post by rbytes »

I just discovered this handy password manager, and I like it a lot. I am curious, though, why there isn't an error trap for when a user enters the incorrect key for a previously encrypted file. Instead of just giving an error message and allowing me to retry, the script crashes with a DIM error.
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Password manager for iPhone2 and up (modified)

Post by Henko »

ricardobytes wrote:I just discovered this handy password manager, and I like it a lot. I am curious, though, why there isn't an error trap for when a user enters the incorrect key for a previously encrypted file. Instead of just giving an error message and allowing me to retry, the script crashes with a DIM error.
While testing, i also tried a wrong key (of course). The result was no crash, but a nonsense translation of the encrypted data. I decided that that whas a nice effect of using a wrong key. I did not experience a program abort.

On the other hand: how to create an error trap for that situation? To my knowledge there is/was no "on error goto" statement in SB, and of course the "master key" of this app should not be saved in a readable form in the SB environment to enable the app to check inputted keys on validity.
The decryption routine just grabs the encryptes data and any inputted key and does its job.
So, you raised an interesting problem: how to check for the valid key, if it is saved nowhere, or how to trap an abend error if it occurs?

Post Reply