Platform SDK: RAS/Routing and RAS

RasGetCredentials

The RasGetCredentials function retrieves the user credentials associated with a specified RAS phone-book entry.

DWORD RasGetCredentials(
  LPCTSTR lpszPhonebook,            // pointer to the full path and
                                    //  file name of a phone-book file
  LPCTSTR lpszEntry,                // pointer to the name of a
                                    //  phone-book entry
  LPRASCREDENTIALS lpCredentials    // pointer to structure that
                                    //  receives credentials
);

Parameters

lpszPhonebook
Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file. If this parameter is NULL, the function uses the current default phone-book file. The default phone-book file is the one selected by the user in the User Preferences property sheet of the Dial-Up Networking dialog box.
lpszEntry
Pointer to a null-terminated string that contains the name of a phone-book entry.
lpCredentials
Pointer to a RASCREDENTIALS structure that receives the user credentials associated with the specified phone-book entry. Before calling RasGetCredentials, set the dwSize member of the structure to sizeof(RASCREDENTIALS), and set the dwMask member to indicate the credential information to retrieve. When the function returns, dwMask indicates the members that were successfully retrieved.

Return Values

If the function succeeds, the return value is zero.

If the function fails, the return value is one of the following error codes.

Value Meaning
ERROR_CANNOT_OPEN_PHONEBOOK The specified phone book cannot be found.
ERROR_CANNOT_FIND_PHONEBOOK_ENTRY The specified entry does not exist in the phone book.
ERROR_INVALID_PARAMETER The lpCredentials parameter was NULL.
ERROR_INVALID_SIZE The dwSize member of the RASCREDENTIALS structure is an unrecognized value.

Remarks

The RasGetCredentials function retrieves the credentials of the last user in order to connect using the specified phone-book entry, or the credentials subsequently specified in a call to the RasSetCredentials function for the phone-book entry.

The RasGetCredentials function retrieves the user credentials that are stored securely for the specified phone-book entry. This function is the preferred way of securely retrieving the credentials associated with a RAS phone-book entry. RasGetCredentials supersedes the RasGetEntryDialParams function, which may not be supported in future releases of Windows 2000.

Windows 2000 and later versions: RasGetCredentials does not return the actual password. Instead, the szPassword member of the RASCREDENTIALS structure contains a handle to the saved password. You can substitute this handle for the saved password in subsequent calls to RasSetCredentials and RasDial. When presented with this handle, RasDial will retrieve and use the saved password The value of this handle may change in future versions of the operating system; do not develop code that depends on the contents or format of this value.

Windows 2000 and later versions: The dwMask member of RASCREDENTIALS contains the RASCM_Password flag if the system has saved a password for the specified entry. If the system has no password saved for this entry, dwMask does not contain RASCM_Password.

The following sample code retrieves the credentials for the phone-book entry with the name "mazy".

ZeroMemory(&lpCred, sizeof(lpCred));
lpCred.dwSize = sizeof(RASCREDENTIALS);
lpCred.dwMask=RASCM_UserName | RASCM_Password | RASCM_Domain ;
res = RasGetCredentials(NULL, "mazy", &lpCred);
if(res == 0)
    printf("The following credentials were retreived:\n%s\n%s\n%s\n",
      lpCred.szUserName,lpCred.szPassword,lpCred.szDomain);
else
    printf("Error: %u\n",res);

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Ras.h.
  Library: Use Rasapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Remote Access Service (RAS) Overview, Remote Access Service Functions, RASCREDENTIALS, RasGetEntryDialParams, RasSetCredentials