Add the -l switch functionality
Using a numeric prefix argument when calling either `dispass' or `dispass-create' will invoke dispass with the -l switch to cut passwords down to a certain size.
This commit is contained in:
parent
99e40ccc0f
commit
d547d846c6
2 changed files with 51 additions and 13 deletions
10
README.rst
10
README.rst
|
@ -53,6 +53,16 @@ to generate a new password.
|
||||||
The only real difference between the two is that `dispass-create`
|
The only real difference between the two is that `dispass-create`
|
||||||
asks to confirm the password. Both will ask for a label.
|
asks to confirm the password. Both will ask for a label.
|
||||||
|
|
||||||
|
When a numeric argument is used when calling either `dispass-create`
|
||||||
|
or `dispass`, that argument is sent to the dispass program along with
|
||||||
|
the `-l` switch. This cuts the length of the password to that many
|
||||||
|
characters. For example::
|
||||||
|
|
||||||
|
C-5 M-x dispass<RET> test<RET> test<RET>
|
||||||
|
|
||||||
|
will generate a password of 5 characters for label "test" and password
|
||||||
|
"test".
|
||||||
|
|
||||||
Once a password has been generated it is inserted into the kill
|
Once a password has been generated it is inserted into the kill
|
||||||
ring and the system's clipboard so it can be easily inserted into
|
ring and the system's clipboard so it can be easily inserted into
|
||||||
password field, this makes the generated password easy to see in
|
password field, this makes the generated password easy to see in
|
||||||
|
|
54
dispass.el
54
dispass.el
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemsen <tom@ryuslash.org>
|
;; Author: Tom Willemsen <tom@ryuslash.org>
|
||||||
;; Created: Jun 8, 2012
|
;; Created: Jun 8, 2012
|
||||||
;; Version: 0.1a7.2
|
;; Version: 0.1a7.3
|
||||||
;; Keywords: encryption, security
|
;; Keywords: encryption, security
|
||||||
|
|
||||||
;; Permission to use, copy, modify, and distribute this software for any
|
;; Permission to use, copy, modify, and distribute this software for any
|
||||||
|
@ -50,6 +50,16 @@
|
||||||
;; The only real difference between the two is that `dispass-create'
|
;; The only real difference between the two is that `dispass-create'
|
||||||
;; asks to confirm the password. Both will ask for a label.
|
;; asks to confirm the password. Both will ask for a label.
|
||||||
|
|
||||||
|
;; When a numeric argument is used when calling either
|
||||||
|
;; `dispass-create' or `dispass', that argument is sent to the dispass
|
||||||
|
;; program along with the -l switch. This cuts the length of the
|
||||||
|
;; password to that many characters. For example:
|
||||||
|
|
||||||
|
;; C-5 M-x dispass<RET>
|
||||||
|
|
||||||
|
;; will generate a password of 5 characters for label "test" and
|
||||||
|
;; password "test".
|
||||||
|
|
||||||
;; Once a password has been generated it is inserted into the kill
|
;; Once a password has been generated it is inserted into the kill
|
||||||
;; ring and the system's clipboard so it can be easily inserted into
|
;; ring and the system's clipboard so it can be easily inserted into
|
||||||
;; password field, this makes the generated password easy to see in
|
;; password field, this makes the generated password easy to see in
|
||||||
|
@ -63,14 +73,22 @@
|
||||||
|
|
||||||
;; 0.1a7.2 - Kill buffer whenever we're finished with it.
|
;; 0.1a7.2 - Kill buffer whenever we're finished with it.
|
||||||
|
|
||||||
|
;; 0.1a7.3 - Add the possility to cut passwords short by using a
|
||||||
|
;; numeric prefix argument.
|
||||||
|
|
||||||
|
;; - Add `dispass-executable' which holds the location of the
|
||||||
|
;; dispass executable script.
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
(defvar dispass-executable "dispass"
|
||||||
|
"The location of the dispass executable")
|
||||||
|
|
||||||
(defun dispass-process-sentinel (proc status)
|
(defun dispass-process-sentinel (proc status)
|
||||||
"Report PROC's status change to STATUS."
|
"Report PROC's status change to STATUS."
|
||||||
(let ((status (substring status 0 -1))
|
(let ((status (substring status 0 -1))
|
||||||
(buffer (process-buffer proc)))
|
(buffer (process-buffer proc)))
|
||||||
(unless (string-equal status "finished")
|
(unless (string-equal status "finished")
|
||||||
(message "dispass %s" (substring status 0 -1)))
|
(message "dispass %s" status))
|
||||||
|
|
||||||
(unless (eq (current-buffer) proc)
|
(unless (eq (current-buffer) proc)
|
||||||
(kill-buffer buffer))))
|
(kill-buffer buffer))))
|
||||||
|
@ -91,7 +109,7 @@ an eye out for LABEL."
|
||||||
(process-send-string proc
|
(process-send-string proc
|
||||||
(concat (read-passwd string nil) "\n")))
|
(concat (read-passwd string nil) "\n")))
|
||||||
|
|
||||||
((string-match (concat "^[ ]+" ,label " \\(.\\{30\\}\\)$")
|
((string-match (concat "^[ \t]*" ,label "[ \t]*\\(.+\\)$")
|
||||||
string)
|
string)
|
||||||
(let ((buffer (process-buffer proc)))
|
(let ((buffer (process-buffer proc)))
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
|
@ -102,25 +120,35 @@ an eye out for LABEL."
|
||||||
(unless (eq (process-status proc) 'run)
|
(unless (eq (process-status proc) 'run)
|
||||||
(kill-buffer buffer))))))))
|
(kill-buffer buffer))))))))
|
||||||
|
|
||||||
(defun dispass-start-process (label &optional create)
|
(defun dispass-start-process (label create length)
|
||||||
"Start dispass process. When CREATE is non-nil send along the
|
"Start dispass process. When CREATE is non-nil send along the
|
||||||
-c switch to make it ask for a password twice."
|
-c switch to make it ask for a password twice. When LENGTH is
|
||||||
(let ((proc (start-process "dispass" "*dispass*" "dispass"
|
an integer and greater than 0, send along the -l switch with
|
||||||
(if create "-co" "-o") label)))
|
LENGTH."
|
||||||
|
(let ((args `("-o" ,label))
|
||||||
|
proc)
|
||||||
|
(when create
|
||||||
|
(setq args (append '("-c") args)))
|
||||||
|
|
||||||
|
(when (and (integerp length) (> length 0))
|
||||||
|
(setq args (append `("-l" ,(number-to-string length)) args)))
|
||||||
|
|
||||||
|
(setq proc (apply 'start-process "dispass" "*dispass*"
|
||||||
|
dispass-executable args))
|
||||||
(set-process-sentinel proc 'dispass-process-sentinel)
|
(set-process-sentinel proc 'dispass-process-sentinel)
|
||||||
(set-process-filter proc (dispass-process-filter-for label))))
|
(set-process-filter proc (dispass-process-filter-for label))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun dispass-create (label)
|
(defun dispass-create (label &optional length)
|
||||||
(interactive "MLabel: ")
|
(interactive "MLabel: \nP")
|
||||||
"Create a new password for LABEL."
|
"Create a new password for LABEL."
|
||||||
(dispass-start-process label t))
|
(dispass-start-process label t length))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun dispass (label)
|
(defun dispass (label &optional length)
|
||||||
(interactive "MLabel: ")
|
(interactive "MLabel: \nP")
|
||||||
"Recreate a password previously used."
|
"Recreate a password previously used."
|
||||||
(dispass-start-process label))
|
(dispass-start-process label nil length))
|
||||||
|
|
||||||
(provide 'dispass)
|
(provide 'dispass)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue