1 //
2 //	password.c
3 //
4 //	Password support for Win9x
5 //
6 #include <windows.h>
7 #include <tchar.h>
8 
9 typedef BOOL (WINAPI *VERIFYSCREENSAVEPWD)(HWND hwnd);
10 typedef VOID (WINAPI *PWDCHANGEPASSWORD)(LPCTSTR lpcRegkeyname, HWND hwnd,UINT uiReserved1,UINT uiReserved2);
11 
VerifyPassword(HWND hwnd)12 BOOL VerifyPassword(HWND hwnd)
13 {
14 	// Under NT, we return TRUE immediately. This lets the saver quit,
15 	// and the system manages passwords. Under '95, we call VerifyScreenSavePwd.
16 	// This checks the appropriate registry key and, if necessary,
17 	// pops up a verify dialog
18 
19 	HINSTANCE			hpwdcpl;
20 	VERIFYSCREENSAVEPWD VerifyScreenSavePwd;
21 	BOOL				fResult;
22 
23 	if(GetVersion() < 0x80000000)
24 		return TRUE;
25 
26 	hpwdcpl = LoadLibrary(_T("PASSWORD.CPL"));
27 
28 	if(hpwdcpl == NULL)
29 	{
30 		return FALSE;
31 	}
32 
33 
34 	VerifyScreenSavePwd = (VERIFYSCREENSAVEPWD)GetProcAddress(hpwdcpl, "VerifyScreenSavePwd");
35 
36 	if(VerifyScreenSavePwd == NULL)
37 	{
38 		FreeLibrary(hpwdcpl);
39 		return FALSE;
40 	}
41 
42 	fResult = VerifyScreenSavePwd(hwnd);
43 	FreeLibrary(hpwdcpl);
44 
45 	return fResult;
46 }
47 
ChangePassword(HWND hwnd)48 BOOL ChangePassword(HWND hwnd)
49 {
50 	// This only ever gets called under '95, when started with the /a option.
51 	HINSTANCE hmpr = LoadLibrary(_T("MPR.DLL"));
52 	PWDCHANGEPASSWORD PwdChangePassword;
53 
54 	if(hmpr == NULL)
55 		return FALSE;
56 
57 	PwdChangePassword = (PWDCHANGEPASSWORD)GetProcAddress(hmpr, "PwdChangePasswordA");
58 
59 	if(PwdChangePassword == NULL)
60 	{
61 		FreeLibrary(hmpr);
62 		return FALSE;
63 	}
64 
65 	PwdChangePassword(_T("SCRSAVE"), hwnd, 0, 0);
66 	FreeLibrary(hmpr);
67 
68 	return TRUE;
69 }
70