Prompts for a password in a dialog box.
Public Declare Function PWD_Prompt Lib "diCrPKI.dll"
(ByVal strPassword As String, ByVal nPwdLen As Long, ByVal strCaption As String) As Long
nRet = PWD_Prompt(strPassword, nPwdLen, strCaption)
long __stdcall PWD_Prompt(char *szPassword, long nPwdLen, const char *szCaption);
If the user enters a password in the dialog box and clicks "OK", the return value is the length of the password entered in bytes. This could be zero. If the user clicks "Cancel", the return value is -1.
Public Function pwdPrompt
(Optional szCaption As String = "", Optional szPrompt As String = "") As String
static std::string dipki::Pwd::Prompt (const std::string &caption, const std::string &prompt="", int maxChars=1024)
Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. ANSI C users must add one to this value when allocating memory.
The password string is limited to 255 characters. It's up to the developer to protect the secrecy of the password
once it's been entered:
see WIPE_Data()
.
This wrapper function can be used to return a password entered by the user in a dialog box. Note it does not distinguish between an empty password and the user clicking "Cancel".
Public Function pwdPrompt(Optional sCaption As String) As String Dim sPassword As String Dim nLen As Long nLen = 255 sPassword = String(nLen, " ") nLen = PWD_Prompt(sPassword, nLen, sCaption) If nLen < 0 Then Exit Function ElseIf nLen > 0 Then pwdPrompt = Left$(sPassword, nLen) End If ' Clean up local variable Call WIPE_String(sPassword, nLen) End Function
Example to prompt for a password in C:
long pwdlen; char password[256]; pwdlen = PWD_Prompt(password, sizeof(password)-1, "Test"); if (pwdlen >= 0) printf("Password entered=[%s]\n", password); else printf("No password entered\n"); /* ... use password ... */ WIPE_Data(password, pwdlen);