CryptoSys PKI Pro Manual

PWD_Prompt

Prompts for a password in a dialog box.

VBA/VB6 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)

C/C++ Syntax

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

Parameters

szPassword
[out] to receive the password entered by the user.
nPwdLen
[in] specifying the maximum length of the string to be received.
szCaption
[in] specifying a caption for the dialog box (optional).

Returns (VBA/C)

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.

VBA Wrapper Syntax

Public Function pwdPrompt (Optional szCaption As String = "", Optional szPrompt As String = "") As String

.NET Equivalent

Pwd.Prompt Method

C++ (STL) Equivalent

static std::string dipki::Pwd::Prompt (const std::string &caption, const std::string &prompt="", int maxChars=1024)

Remarks

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().

Example (VBA core function)

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]

[PREV: PRF_Bytes...]   [Contents]   [Index]   
   [NEXT: PWD_PromptEx...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.