home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / password / password.asm next >
Assembly Source File  |  1992-11-15  |  9KB  |  204 lines

  1. ;; PASSWORD - password security program with alarm sound.
  2. ;;
  3. ;; To change password after assembling use Dos debug program
  4. ;;
  5. ;; Type: DEBUG PASSWORD.COM
  6. ;;
  7. ;; At the debug prompt type:  F 103 116 0
  8. ;; press enter
  9. ;; this replaces old password with "0"s
  10. ;;
  11. ;; Next type:  E 103 'ANYWORD' press enter
  12. ;; Be sure to include the quotes at beginning and end of password.
  13. ;; ( up to 20 characters in length )
  14. ;; PASSWORD MUST BE IN UPPERCASE
  15. ;;
  16. ;; Type W
  17. ;; press enter to write program to disk
  18. ;;
  19. ;;
  20. ;; This program can be assembled using the A86 or TASM assemblers 
  21. ;;
  22. ;; Not tested with Masm, should work?
  23. ;;
  24. ;; This code is "PUBLIC DOMAIN"
  25. ;;
  26. ;; by William Cravener 11/14/92
  27. ;;
  28. ;-----------------------------------------------------------------------------
  29. ;;
  30. code                    SEGMENT         ; set up code and data section
  31.  
  32. ASSUME          cs:code, ds:code, es:code, ss:code
  33.  
  34. ORG             100h                    ; COM programs begin here
  35.  
  36. main:           jmp     password_code   ; skip over "DATA"
  37. ;;
  38. ;----------------------------------------------------------------------------- 
  39. ;; DATA
  40. ;;
  41. psword                  DB      20 DUP (0) ; room for 20 byte password
  42.  
  43. inpsword                DB      20 DUP (0) ; keys pressed stored here
  44.  
  45. prompt                  DB      13, 10, 'Please enter system password: ', 0
  46. match                   DB      13, 10, 10, 'Password Accepted!', 13, 10, 10, 0
  47. start                   DB      0
  48. rightlimit              DB      0
  49. ;;
  50. ;-----------------------------------------------------------------------------
  51. password_code:
  52.         mov     ah, 8                   ; get current screen color
  53.         mov     bh, 0
  54.         int     10h
  55.         mov     bh, ah                  ; place color in bh
  56.         mov     ah, 6                   ; service "6" scroll screen
  57.         mov     al, 0                   ; scroll 25 rows
  58.         mov     cx, 0                   ; upper left
  59.         mov     dx, 184fh               ; lower right
  60.         int     10h
  61.         mov     ah, 2                   ; set cursor
  62.         mov     bh, 0
  63.         mov     dx, 0a00h               ; at about the center row
  64.         int     10h
  65.         mov     si, OFFSET prompt       ; output the prompt 
  66.         call    print_string 
  67.         mov     ah, 3                   ; get cursor location 
  68.         mov     bh, 0
  69.         int     10h
  70.         mov     start, dl               ; save cursor start position
  71.         push    dx                      ; push cursor location on stack
  72.         add     dl, 20                  ; add 20 places -
  73.         mov     rightlimit, dl          ; to the right - maximum
  74.         pop     dx                      ; restore cursor location
  75.         mov     di, OFFSET inpsword     ; point di to "inpsword"
  76.         push    di                      ; push it on the stack
  77.         mov     al, 0                   ; be sure any previous
  78.         mov     cx, 20                  ; attempt is flushed out
  79.         repe    stosb
  80.         pop     di                      ; pop "inpsword" off stack 
  81. key_input:
  82.         xor     ax, ax                  ; get key pressed
  83.         int     16h                     ; BIOs key input
  84.         cmp     ah, 1ch        
  85.         je      completed               ; "ENTER" key pressed
  86.         cmp     ah, 0eh
  87.         je      moveleft                ; "BACKSPACE" key pressed
  88.         cmp     al, 20h
  89.         jl      key_input               ; return if not valid key
  90.         cmp     dl, rightlimit          ; 20 character limit
  91.         jge     password_code
  92.         call    uppercase               ; make upper case if need be
  93.         push    ax                      ; push character on stack
  94.         mov     ah, 0ah                 ; print a smilly face
  95.         mov     al, 1                   ; smilly value
  96.         mov     bh, 0                   ; must be page "0"
  97.         mov     cx, 1                   ; print 1 smilly face
  98.         int     10h
  99.         mov     ah, 3                   ; get cursor location
  100.         int     10h
  101.         inc     dl                      ; move it to the right
  102.         mov     ah, 2                   ; set cursor
  103.         mov     bh, 0
  104.         int     10h
  105.         pop     ax                      ; pop character off stack
  106.         stosb                           ; store it to "inpsword"
  107.         jmp     key_input               ; go get next key press
  108. completed:
  109.         cmp     BYTE PTR [inpsword], 0  ; if equal "0" nothing entered
  110.         jne     ok_checkit              ; is something there
  111.         jmp     password_code           ; "no" go try again
  112. ok_checkit:
  113.         jmp     checkit                 ; "yes" go compare strings
  114. moveleft:
  115.         call    to_the_left             ; user pressed backspace key
  116.         jmp     key_input               ; go get a key press
  117. checkit:
  118.         mov     cx, 20                  ; set up counter for compare
  119.         mov     si, OFFSET psword       ; the assigned password
  120.         mov     di, OFFSET inpsword     ; user entered password
  121.         cld                             ; clear DF flag for compare
  122.         repe    cmpsb
  123.         cmp     cx, 0                   ; did CX reach zero?
  124.         jz      gotmatch                ; jump if they match
  125.         call    alarm                   ; illegal attempt - sound alarm
  126.         jmp     password_code           ; go try again
  127. gotmatch:
  128.         mov     si, OFFSET match        ; assume a match
  129.         call    print_string            ; print out message
  130. alldone: 
  131.         mov     ax, 4c00h               ; return to system
  132.         int     21h
  133. ;--------------------------------------
  134. alarm:  
  135.         mov     bp, 10                  ; number of passes
  136. next:
  137.         mov     dx, 200                 ; repeat count of inner loop
  138.         mov     bx, 700                 ; start frequency low
  139.         mov     al, 0b6h                ; magic number
  140.         out     43h, al                 ; send it
  141. back:
  142.         mov     ax, bx                  ; place frequency in (ax)
  143.         out     42h, al                 ; send LSB
  144.         mov     al, ah                  ; put MSB in (al)
  145.         out     42h, al                 ; send it
  146.         in      al, 61h                 ; get value from port
  147.         or      al, 03h                 ; ORing will turn speaker on
  148.         out     61h, al                 ; send it
  149.         dec     bx                      ; decrementing rises frequency 
  150.         mov     cx, 1000                ; delay count in (cx)
  151. looper:                                  
  152.         loop    looper                  ; do nothing loop so we can hear sound
  153.         dec     dx                      ; decrement our repeat count
  154.         jnz     back                    ; if not = 0 go do again
  155.         in      al, 61h                 ; get port value
  156.         and     al, 0fch                ; ANDing turns speaker off
  157.         out     61h, al
  158.         dec     bp
  159.         jz      done
  160.         jmp     next
  161. done:        
  162.         ret
  163. ;---------------------------------------
  164. to_the_left:                            ; backspace subroutine
  165.         cmp     dl, start               
  166.         jle     nomo
  167.         dec     dl                      ; move back 1 space
  168.         mov     ah, 2                   ; and set cursor
  169.         mov     bh, 0
  170.         int     10h
  171.         dec     di                      ; decrement memory pointer
  172.         mov     BYTE PTR [di], 0        ; place 0 at that location
  173.         mov     ah, 0ah
  174.         mov     al, ' '                 ; print a blank space
  175.         mov     cx, 1                   ; at cursor position
  176.         int     10h
  177. nomo:   
  178.         ret
  179. ;----------------------------------
  180. print_string:                           ; prints string to consol
  181.         lodsb
  182.         cmp     al, 0                   ; 0 indicates end of string
  183.         jz      endofit
  184.         mov     ah, 0eh
  185.         mov     bh, 0
  186.         int     10h
  187.         jmp     print_string
  188. endofit:
  189.         ret
  190. ;----------------------------------
  191. uppercase:                              ; make character uppercase
  192.         cmp     al,'a'                  ; if neccessary
  193.         jb      isup
  194.         cmp     al,'z'
  195.         ja      isup
  196.         sub     al,20h
  197. isup:
  198.         ret
  199. ;-----------------------------------------------------------------------------
  200. code                    ENDS            ; end of code
  201.  
  202. END             main
  203.  
  204.