Requesting a Password

AutoCAD AutoLISP & Visual LISP

 
Requesting a Password
 
 
 

The following examples show how to use a simple dialog box to request a password from users.

The getpass.dcl file defines a dialog box named passdlg, which contains two tiles: the edit_box tile where the user enters the password, and the ok_cancel tile. It uses the password_char DCL attribute to mask the text a user enters:

// GETPASS.DCL
//
passdlg : dialog {
  label = "Password Protected";
  : edit_box {
    label = "Password:";
    edit_width = 20;
    key = "password";
    password_char = "?";
  }
  ok_cancel;
}

The getpass.lsp file defines the GETPASS function. This function loads the getpass.dcl file and displays the passdlg dialog box. When a user enters text into the edit box, it is masked by the password_char character defined in the DCL file. The action assigned to the edit box ensures that the characters entered by the user are set to the pass variable:

;; GETPASS.LSP
;;
(defun GETPASS ( / dcl_id pass )
  (setq dcl_id (load_dialog "getpass.dcl"))
  (if (new_dialog "passdlg" dcl_id)
    (progn
      (action_tile "password" "(setq pass $value)")
      (start_dialog)
      (unload_dialog dcl_id)
    )
    (princ "Error: Unable to load GETPASS.DCL. ")
  )
  pass
)

The GETPASS function returns the string entered by the user.