home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / portfoli / acdpw2 / pw2.asm < prev    next >
Encoding:
Assembly Source File  |  1991-08-21  |  5.3 KB  |  188 lines

  1. %TITLE  "Password for Portfolio"
  2.  
  3. ; /***************************************************************
  4. ; * password.c -- simple password protection for the portfolio   *
  5. ; *                                                              *
  6. ; * Author : Alan Davis CIS:72317,3661                           *
  7. ; *                                                              *
  8. ; * Original Implementation : TurboC v2.0                        *
  9. ; * Current Implementation  : Turbo Assembler v1.0               *
  10. ; *                                                              *
  11. ; * edits                                                        *
  12. ; * 1.1  added c_break protection                                *
  13. ; * 2.0  recode in assembler, (saved 8K in exe size)             *
  14. ; ***************************************************************/
  15. ; Portions Copyright 1989 by Tom Swan
  16.  
  17.     IDEAL
  18.     DOSSEG
  19.     MODEL    small
  20.     STACK    32
  21.  
  22. ;----- Equates
  23. MaxLen        EQU    10  ; length of password
  24.  
  25. cr        EQU    13  ; ascii cr
  26. lf        EQU    10  ; ascii lf
  27. space           EQU     32  ; ascii space
  28.  
  29. INCLUDE "DOSMACS.ASM"
  30.  
  31.     DATASEG
  32.  
  33. exitCode    db    0
  34.  
  35. Prompt          db      'Password : ',0
  36. Usage        db    'passwd V2.0',cr,lf
  37.         db    'Alan Davis, Oct 1990',cr,lf,lf
  38.                 db      'Usage : passwd phlugg',cr,lf
  39.                 db      'Where phlugg is the password',cr,lf
  40.                 db      'Password is limited to 10 chars',cr,lf,0
  41.  
  42. PWString    db    MaxLen DUP (?),0
  43. UserPW          db      MaxLen DUP (?),0
  44. blanks          db      21 DUP (space),0
  45. cseg            dw      ?   ; saved vector 
  46. cofs            dw      ?   ; for cbrk int 1Bh
  47. cbseg           dw      ?   ; saved vector 
  48. cbofs           dw      ?   ; for cbrk int 23h
  49.  
  50. INCLUDE "longjmp.inc"
  51.  
  52. Restart         jmpbuf      ; program state buffer
  53.  
  54.     CODESEG
  55.  
  56. ;-----  From: Strings.obj:
  57.  
  58.         EXTRN   StrCopy:proc, StrCompare:proc, StrLength:proc
  59.  
  60. ;-----  From: Strio.obj:
  61.  
  62.     EXTRN    StrReadNE:proc, StrWrite:proc, NewLine:proc, CRnoLF:proc
  63.  
  64. ;-----  From : Params.obj;
  65.  
  66.         EXTRN   Getparams:proc, GetOneParam:proc, ParamCount:proc
  67.  
  68. ;-----  From : Longjmp.obj
  69.  
  70.         EXTRN setjmp:proc, longjmp:proc
  71.  
  72.  
  73. PROC    c_break
  74.  
  75.         mov     ax,1                ; simulated exit code for longjmp
  76.     push    ax                 
  77.     mov     ax,OFFSET Restart   ; stored program state
  78.     push    ax
  79.         call    longjmp             
  80.  
  81.         iret
  82. ENDP    c_break
  83.  
  84. PROC    setcbrk
  85.  
  86.         push    dx
  87.         push    es
  88.         push    ax
  89.         push    bx
  90.  
  91.         DOS_GetVector 01bh          ; set 1st cbrk intr
  92.         mov     [cseg], es          ; store original
  93.         mov     [cofs], bx          ; 1Bh handler address (bios)
  94.         DOS_SetVector 01bh, c_break
  95.  
  96.         DOS_GetVector 023h          ; set 2nd cbrk intr
  97.         mov     [cbseg], es         ; store original
  98.         mov     [cbofs], bx         ; 23h handler address (dos)
  99.         DOS_SetVector 023h, c_break
  100.  
  101.         pop     bx
  102.         pop     ax
  103.         pop     es
  104.         pop     dx
  105.  
  106.         ret
  107. ENDP    setcbrk
  108.  
  109. Start:
  110.     mov    ax,@data        ; Set ax to data segment
  111.     mov    es,ax           ; set es to data segment
  112.        
  113.         push    ds              ; save ds for getparams
  114.         mov     ds,ax
  115.         call    setcbrk         ; disable c_break
  116.         pop     ds
  117.  
  118.         call    GetParams       ; Get parameters with ds = PSP
  119.  
  120.         call    ParamCount      ; Get number of parameter into dx
  121.  
  122. ; check command line
  123.         push    dx              ; Save dx on stack
  124.         or      dx,dx           ; does dx = 0?
  125.         jz      Help            ; Display usage
  126.         pop     dx              ; restore number of params
  127.         cmp     dx,1            ; Is there only 1 param?
  128.         jne     Help            ; No, display usage
  129.  
  130.         xor     cx,cx           ; Parameter 0 (first one)
  131.         call    GetOneParam
  132.         mov     dx,di           ; adr string w/ ds:dx
  133.  
  134.         call    StrLength       ; is pw longer than 10 chars
  135.         cmp     cx,MaxLen
  136.         jg      help
  137.  
  138.         mov     si,dx               ; save password
  139.         mov     di,OFFSET PWString
  140.         call    StrCopy
  141.  
  142.         jmp     clearline           ; just to set setjmp target
  143. again:
  144.         mov     di, OFFSET Prompt   ; display prompt
  145.         call    StrWrite
  146.  
  147.         mov     di,OFFSET UserPW    ; set adr of entered pw
  148.         mov     cl,MaxLen           ; can only be MaxLen chars
  149.         call    StrReadNE           ; get it, don't echo
  150.  
  151.         mov     si, OFFSET PWString ; compare the two strings
  152.         mov     di, OFFSET UserPW
  153.         call    StrCompare
  154.         jne     clearline           ; if not right pw, clear line 
  155.                                     ; and ask again
  156.         
  157. done:   ; pw verified, cleanup and exit
  158.  
  159.         DOS_RestoreVector 01Bh,cseg,cofs    ; restore C-break
  160.     DOS_RestoreVector 023h,cbseg,cbofs  ; handler vectors
  161.  
  162. Exit:
  163.     mov    ah,04Ch
  164.     mov    al,[exitCode]
  165.     int    21h
  166.  
  167. clearline:  ; This is where we return to on Ctrl-C
  168.  
  169.         push    ax
  170.     mov     ax,OFFSET Restart
  171.         push    ax
  172.     call    setjmp
  173.         pop ax
  174.  
  175.         call    CRnoLF
  176.         mov     di, OFFSET blanks
  177.         call    StrWrite
  178.         call    CRnoLF
  179.         jmp     again
  180.  
  181. Help:
  182.     mov    di,OFFSET Usage
  183.     call    StrWrite
  184.         jmp     Exit
  185.  
  186.  
  187.     END    Start
  188.