Bob’s Notebook: Password Protection

See all articles from Sinc-Link v4 n6
Author(s): Bob Mitchell
Publication: Sinc-Link
Pub Details: Sinc-Link v4 n6 (Volume 4, Issue 6)
Date: November/December 1986
Pages: 11

Since I started writing this column for Sinc-Link, I have been concentrating on the art of programming both in BASIC and in Z80 machine language. I have found that typing in BASIC programs and understanding the intent of every routine and line has helped me to write some fairly complex programs. Also, after laboriously typing in a lot of machine code routines and dissecting them via a good disassembler, I have been able to understand some of the routines well enough to at least be able to modify them to suit my own applications.

There have been many excellent BASIC programs published in such magazines as Your Computer and ZX Computing and in those programs have been some very good routines that I have been able to work into my own concoctions. The demonstration tape provided by Timex with the TS2068 is a goldmine of such useful ideas. By examining the way ON ERR was used in ‘budge’ on that tape, I was able to make good use of a rather tricky command: listed below is an application of ON ERR in a password routine which will work with programs saved on the Larken Disk system.

First, a comment about the password routine which appeared in the May-Jun issue: this will not work very well since there must be an ON ERR RESET statement at the beginning of line 100; otherwise, the program will hang up. Furthermore, the password routine can be defeated by using the Sinclair MERGE command. One of the shortcomings of the Larken system is that it does not support ‘merge’; you have to do all your MERGEing via tape. But every cloud has a silver lining and the lack of merge with LDOS allows the password routine to work acceptably.

I found that an ‘ON ERR GO TO’ statement was needed just before the LDOS save statement. This stops the unauthorized user from using the Caps Shift and Break keys to stop the program from loading from disk and so see the listing and data. This you do not want to happen! This is shown at line 3533.

Now, no matter what keys you press, the program loads and presents the prompt “Enter password”. You can try and try but you must know the right password or words or you simply cannot list or otherwise enter the program. With a correct password, the program advances to the autostart line (where there will be an ON ERR RESET or else!) and the break key will be working normally. Lines 4020 and 4030 are needed to complete the loop if a proper password is not entered. Line 3530 sets up the file name in s$ for saving via LDOS48.

Note my use of two passwords in line 4010. You may have as many or few as you wish. These are just examples.

3520 REM SAVE ROUTINE
3530 CLS : LET S$="fax"+Y$+".B1": PRINT "SAVING AS: ";S$
3531 OUT 84,64: RANDOMIZE USR 63488
3532 REM load "LDOS48.C5"
3533 ON ERR GO TO 3536: OUT 84,64: RANDOMIZE USR 48000
3534 REM save s$
3536 ON ERR GO TO 4000
4000 CLS : INPUT AT 0,0;"Enter password "; LINE p$
4010 IF p$="password" OR p$="unlock" THEN GO TO 610
4020 ON ERR GO TO 3536
4030 ON ERR CONTINUE

At line 4000, as you enter your password, it will appear on the screen. Afraid of someone looking over your shoulder? Try the following changes:

4000 CLS: PRINT AT 19,0;"Enter password"
4002 PAUSE 30
4004 POKE 23658,0: POKE 23607,200
4006 INPUT LINE p$
4008 POKE 23607,60

Finally, if you use the BASIC compiler Timachine, you will know that it does not support ON ERR. Not to worry! You can put the password routine into a loader program which will contain the start addresses that will make it almost impossible for anyone to invade the privacy you have set up!

NOV 4 1986

R.H.Mitchell

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.