home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / term-lock.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  6.2 KB  |  180 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!apple!oracle!news Wed Feb  7 16:23:37 1990
  2. ;Article 1319 of comp.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!apple!oracle!news
  4. ;From nhess@dvlseq.oracle.com (Nate Hess)
  5. ;Newsgroups: comp.emacs
  6. ;Subject: Terminal lock program for GNU Emacs
  7. ;Keywords: ASCII terminal lock
  8. ;Message-ID: <1990Feb5.183922.20072@oracle.com>
  9. ;Date: 5 Feb 90 18:39:22 GMT
  10. ;Sender: news@oracle.com
  11. ;Reply-To: nhess@dvlseq.oracle.com (Nate Hess)
  12. ;Organization: Oracle Corporation, Belmont, CA
  13. ;Lines: 163
  14. ;
  15. ;Here is a little something that I wrote a couple of years ago.  Someone
  16. ;might find it useful; I used it on my terminal at home all the time to
  17. ;prevent Binky, my cat, from doing nasty things to my Emacs session.
  18. ;
  19. ;To my knowledge, no one has been able to break the lock.
  20. ;
  21. ;
  22. ;------------------------------ cut here ------------------------------
  23. ;;;
  24. ;;;    Copyright (C) 1990 Nathan R. Hess
  25. ;;;
  26. ;;;    Verbatim copies of this file may be freely redistributed.
  27. ;;;
  28. ;;;    Modified versions of this file may be redistributed provided
  29. ;;;    that this notice remains unchanged, the file contains prominent
  30. ;;;    notice of author and time of modifications, and redistribution
  31. ;;;    of the file is not further restricted in any way.
  32. ;;;
  33. ;;;    This file is distributed `as is', without warranties of any kind.
  34. ;;;
  35. ;;;
  36. ;;;    Author:  Nathan Hess  (nhess@oracle.com)
  37. ;;;
  38. ;;;    Purpose:  Terminal Lock utility for GNU Emacs;
  39. ;;;          intended primarily for use on ASCII terminals.
  40. ;;;
  41. ;;;    Pseudo-Disclaimer:  This is a couple hour hack.
  42. ;;;
  43. ;;;    Change History:
  44. ;;;    11/02/87 NRH    First version.
  45. ;;;    11/19/87 NRH    Don't echo the password, and ask the user to
  46. ;;;            verify it.  Also, added variable for longest
  47. ;;;            allowable password.
  48. ;;;    12/15/87 NRH    Kick up the LOCKED buffer to cover the whole
  49. ;;;                     screen, and restore the previous window
  50. ;;;                     configuration when proper password is given.
  51. ;;;    01/07/88 NRH    Prompt the user for an optional message to be
  52. ;;;                     displayed along with the "enter password"
  53. ;;;                     message.  A worthwhile possible enhancement to
  54. ;;;                     this would be to have a set of canned messages
  55. ;;;                     ("Gone to lunch", etc.) displayed in a menu.
  56. ;;;                     The user would either pick one of those or would
  57. ;;;                     type one in.
  58. ;;;    02/01/88 NRH    Added a default signature to the optional message.
  59. ;;;    02/05/90 NRH    Some cleanup before posting.
  60. ;;;
  61. ;;
  62. ;;
  63. (defvar max-term-lock-password-length 100
  64.   "*Largest password allowed in term-lock mode.")
  65.  
  66. (defvar term-lock-signature nil
  67.   "*Default signature at bottom of optional message, none if nil.")
  68.  
  69. (defun term-lock ()
  70.   "Prompts user for a password, verifies the password,
  71. then won't leave the ***LOCKED*** buffer 'til it's typed in again.
  72. Prompts for an optional message to display in the middle of the screen."
  73.   (interactive)
  74.   (let ((echo-keystrokes 0)
  75.     first-try
  76.     informative-message
  77.     second-try)
  78.     (setq first-try (read-string-no-echo "Enter password:"))
  79.     (setq second-try (read-string-no-echo "Verify password:"))
  80.     (if    (not (string-equal first-try second-try))
  81.     (message "Password not verified.")
  82.       (if (> (length first-try) max-term-lock-password-length)
  83.       (message "Password longer than max-term-lock-password-length")
  84.     (if (= (length first-try) 0)
  85.         (message "Null password is not valid.")
  86.       (setq informative-message
  87.         (read-string "Enter optional message: "))
  88.       (setq window-configuration-before-lock
  89.         (current-window-configuration))
  90.       (switch-to-buffer "***LOCKED***")
  91.       (delete-other-windows)
  92.       (insert "Enter password followed by <CR> to exit")
  93.       (center-line)
  94.       (goto-char (point-max))
  95.       ; This is obviously a klunky way of centering text...
  96.       (insert "\n\n\n\n\n\n\n\n\n\n")
  97.       (insert informative-message)
  98.       (insert "\n")
  99.       (if (and
  100.         (stringp term-lock-signature)
  101.         (not (string-equal informative-message "")))
  102.           (insert term-lock-signature "\n"))
  103.       (center-region
  104.        (save-excursion
  105.          (search-backward "\n\n\n")
  106.          (+ (point) 2))
  107.        (point-max))
  108.       (goto-char (point-min))
  109.       ; Just to rub it in...  :->#
  110.       (setq buffer-read-only t)
  111.       (setq typed-password "")
  112.       (term-lock-mode first-try)))))
  113. ) ;term-lock
  114.  
  115. (defun term-lock-mode (password)
  116.   "Kicks up a '***LOCKED***' buffer, and waits for the password."
  117.   (kill-all-local-variables)
  118.   (setq major-mode 'term-lock-mode)
  119.   (setq mode-name "Term-Lock")
  120.   (setq initial-password password)
  121.   (use-local-map term-lock-map)
  122. ) ;term-lock-mode
  123.  
  124. (defun add-to-typed-password ()
  125.   "Append the character to the typed password."
  126.   (interactive)
  127.   (setq typed-password (concat typed-password
  128.                    (substring (recent-keys) -1)))
  129.   (if (> (length typed-password) max-term-lock-password-length)
  130.       (progn
  131.     (setq typed-password "")
  132.     (message "Did something fall on your terminal?")
  133.     (sit-for 3 t))
  134.     (message ""))
  135. ) ;add-to-typed-password
  136.  
  137. (defun check-typed-password ()
  138.   "Compare passwords, and exit if they are the same."
  139.   (interactive)
  140.   (if (string-equal initial-password typed-password)
  141.       (progn
  142.     (kill-buffer (current-buffer))
  143.     (set-window-configuration window-configuration-before-lock))
  144.     (setq typed-password "")
  145.     (message "Get a real password."))
  146. ) ;check-typed-password
  147.  
  148. (defun read-string-no-echo (msg)
  149.   "Return a string read from the keyboard, without echo to the minibuffer.
  150. Keep MSG, a string, in the minibuffer during entry of the string."
  151.   (interactive)
  152.   (message msg)
  153.   (let ((char (read-char))
  154.     (cursor-in-echo-area t)
  155.     (string ""))
  156.     (while (/= char ?\C-m)
  157.       (setq string (concat string (list char)))
  158.       (message msg)
  159.       (setq char (read-char)))
  160.     string)
  161. ) ;read-string-no-echo
  162.  
  163. (setq term-lock-map (make-keymap))
  164. ; Note that we are rebinding C-g, here.  Sport Death!
  165. (substitute-key-definition nil 'add-to-typed-password term-lock-map)
  166. (define-key term-lock-map "\C-l" 'recenter)
  167. (define-key term-lock-map "\C-m" 'check-typed-password)
  168. ;------------------------------ cut here ------------------------------
  169. ;
  170. ;
  171. ;Hope y'all find this useful!
  172. ;--woodstock
  173. ;-- 
  174. ;       "What I like is when you're looking and thinking and looking
  175. ;       and thinking...and suddenly you wake up."   - Hobbes
  176. ;
  177. ;nhess@dvlseq.oracle.com or ...!uunet!oracle!nhess or (415) 598-3046
  178.  
  179.  
  180.