And PWD_PromptEx prompt 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)
String to receive the password entered by the user.Long specifying the maximum length of the string to be received.String specifying a caption for the dialog box (optional).String specifying the prompt (default="Enter password:").Long option flags: not used in this release. Specify zero.
long _stdcall PWD_Prompt(char *szPassword, long nPwdLen, const char *szCaption);
Long: 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.
Pwd.Prompt Method (Int32, String)
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);