Pocket PC password protection

Vassili Philippov (vasja@spbteam.com), September 03, 2001.

Introduction

Pocket PC has a built-in password protection that allows locking a device with a password. This article describes how to set a system password and "require password when device is turned on" flag.

What You Need

Background

Pocket PC has a build-in password represented with a string. Default password dialog allows entering only 4 characters password that consists of digitals (0..9). But you can set any string as a password if you write your own password prompt and a password applet in Control Panel.

There is also a "require password when device is turned on" flag. We will call it "password active" flag for short. If this flag is set then the device cannot be turned on without entering a password.

Using STPasswordManager library

The easiest way for changing password setting is to use STPasswordManager library. This library wraps working with coredll.dll and registry. All you need is to create an instance of CSTPasswordManager class and call necessary methods. Like:

UpdateData(TRUE); CSTPasswordManager pm; pm.SetPasswordActive(m_strPassword, m_bPasswordActive);

Changing password settings

If you want to work with low-level password setting then you have to use functions defined in coredll.dll library. These are:

They are responsible for setting a system password and setting and getting "password active" flag.

Here are signatures for these functions:

BOOL SetPassword(LPWSTR lpszOldpassword, LPWSTR lspzNewPassword); BOOL SetPasswordActive(BOOL bActive, LPWSTR lpszPassword); BOOL GetPasswordActive();

To use them you have to load coredll.dll library using LoadLibrary function, then take the function address using GetProcAddress function and typecast this address to the function type defined using necessary signature. Here is a sample code for that:

//Change password from "1234" to "4321" typedef BOOL SetPasswordProc(LPWSTR lpszOldpassword, LPWSTR lspzNewPassword); SetPasswordProc *procSetPassword; HMODULE hModule = ::LoadLibrary(_T("coredll.dll")); FARPROC pProc; pProc = GetProcAddress(hModule, _T("SetPassword")); procSetPassword = (SetPasswordProc*)pProc; procSetPassword(_T("1234"), _T("4321"));

Pocket PC also stores information about "password active" flag in registry in HKEY_CURRENT_USER\ControlPanel\Owner\PowrPass value. So this flag is stored in two different locations: somewhere in inaccessible memory and in registry. You have to update both these locations.

Conclusion

Although it's undocumented you can change the system password and "password active" flag. The easiest way is to use STPasswordManager library that encapsulates all necessary functionality.

Related resources: