CryptoSys PKI Toolkit Manual

PWD_Prompt

And PWD_PromptEx prompt for a password in a dialog box.

VB6/VBA Syntax

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)

Parameters

strPassword
[out] String to receive the password entered by the user.
nPwdLen
[in] Long specifying the maximum length of the string to be received.
strCaption
[in] String specifying a caption for the dialog box (optional).
strPrompt
[in] String specifying the prompt (default="Enter password:").
nOptions
[in] Long option flags: not used in this release. Specify zero.

C/C++ Syntax

long _stdcall PWD_Prompt(char *szPassword, long nPwdLen, const char *szCaption);

Returns (VB6/C)

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.

.NET Equivalent

Pwd.Prompt Method (Int32, String)

Remarks

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.

Example

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);

See Also

PWD_PromptEx

[Contents] [Index]

[HOME]   [NEXT: PWD_PromptEx...]

Copyright © 2004-12 D.I. Management Services Pty Ltd. All rights reserved.