[USRMGR]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 24 Aug 2013 20:50:21 +0000 (20:50 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 24 Aug 2013 20:50:21 +0000 (20:50 +0000)
Implement the set password function.

svn path=/trunk/; revision=59813

reactos/dll/cpl/usrmgr/users.c

index 97b582e..8ade77f 100644 (file)
@@ -32,13 +32,13 @@ CheckPasswords(HWND hwndDlg,
                INT nIdDlgItem1,
                INT nIdDlgItem2)
 {
-    TCHAR szPassword1[256];
-    TCHAR szPassword2[256];
+    TCHAR szPassword1[PWLEN];
+    TCHAR szPassword2[PWLEN];
     UINT uLen1;
     UINT uLen2;
 
-    uLen1 = GetDlgItemText(hwndDlg, nIdDlgItem1, szPassword1, 256);
-    uLen2 = GetDlgItemText(hwndDlg, nIdDlgItem2, szPassword2, 256);
+    uLen1 = GetDlgItemText(hwndDlg, nIdDlgItem1, szPassword1, PWLEN);
+    uLen2 = GetDlgItemText(hwndDlg, nIdDlgItem2, szPassword2, PWLEN);
 
     /* Check the passwords */
     if (uLen1 != uLen2 || _tcscmp(szPassword1, szPassword2) != 0)
@@ -50,7 +50,6 @@ CheckPasswords(HWND hwndDlg,
         return FALSE;
     }
 
-
     return TRUE;
 }
 
@@ -61,11 +60,18 @@ ChangePasswordDlgProc(HWND hwndDlg,
                       WPARAM wParam,
                       LPARAM lParam)
 {
+    PUSER_INFO_1003 userInfo;
+    INT nLength;
+
     UNREFERENCED_PARAMETER(wParam);
 
+    userInfo = (PUSER_INFO_1003)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
     switch (uMsg)
     {
         case WM_INITDIALOG:
+            userInfo = (PUSER_INFO_1003)lParam;
+            SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
             break;
 
         case WM_COMMAND:
@@ -73,11 +79,22 @@ ChangePasswordDlgProc(HWND hwndDlg,
             {
                 case IDOK:
                     if (CheckPasswords(hwndDlg, IDC_EDIT_PASSWORD1, IDC_EDIT_PASSWORD2))
-                        EndDialog(hwndDlg, 0);
+                    {
+
+                        /* Store the password */
+                        nLength = SendDlgItemMessage(hwndDlg, IDC_EDIT_PASSWORD1, WM_GETTEXTLENGTH, 0, 0);
+                        if (nLength > 0)
+                        {
+                            userInfo->usri1003_password = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
+                            GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD1, userInfo->usri1003_password, nLength + 1);
+                        }
+
+                        EndDialog(hwndDlg, IDOK);
+                    }
                     break;
 
                 case IDCANCEL:
-                    EndDialog(hwndDlg, 0);
+                    EndDialog(hwndDlg, IDCANCEL);
                     break;
             }
             break;
@@ -90,6 +107,52 @@ ChangePasswordDlgProc(HWND hwndDlg,
 }
 
 
+static VOID
+UserChangePassword(HWND hwndDlg)
+{
+    TCHAR szUserName[UNLEN];
+    USER_INFO_1003 user;
+    INT nItem;
+    HWND hwndLV;
+    NET_API_STATUS status;
+
+    ZeroMemory(&user, sizeof(USER_INFO_1003));
+
+    hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);
+    nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
+    if (nItem == -1)
+        return;
+
+    /* Get the new user name */
+    ListView_GetItemText(hwndLV,
+                         nItem, 0,
+                         szUserName,
+                         UNLEN);
+
+    if (DialogBoxParam(hApplet,
+                       MAKEINTRESOURCE(IDD_CHANGE_PASSWORD),
+                       hwndDlg,
+                       ChangePasswordDlgProc,
+                       (LPARAM)&user) == IDOK)
+    {
+        status = NetUserSetInfo(NULL,
+                                szUserName,
+                                1003,
+                                (LPBYTE)&user,
+                                NULL);
+        if (status != NERR_Success)
+        {
+            TCHAR szText[256];
+            wsprintf(szText, TEXT("Error: %u"), status);
+            MessageBox(NULL, szText, TEXT("NetUserSetInfo"), MB_ICONERROR | MB_OK);
+        }
+    }
+
+    if (user.usri1003_password)
+        HeapFree(GetProcessHeap(), 0, user.usri1003_password);
+}
+
+
 static VOID
 UpdateUserOptions(HWND hwndDlg,
                   PUSER_INFO_3 userInfo,
@@ -407,7 +470,6 @@ UpdateUsersList(HWND hwndListView)
     LV_ITEM lvi;
     INT iItem;
 
-
     for (;;)
     {
         netStatus = NetUserEnum(NULL, 20, FILTER_NORMAL_ACCOUNT,
@@ -441,7 +503,6 @@ UpdateUsersList(HWND hwndListView)
         if (netStatus != ERROR_MORE_DATA)
             break;
     }
-
 }
 
 
@@ -655,11 +716,7 @@ UsersPageProc(HWND hwndDlg,
             switch (LOWORD(wParam))
             {
                 case IDM_USER_CHANGE_PASSWORD:
-                    DialogBoxParam(hApplet,
-                                   MAKEINTRESOURCE(IDD_CHANGE_PASSWORD),
-                                   hwndDlg,
-                                   ChangePasswordDlgProc,
-                                   (LPARAM)NULL);
+                    UserChangePassword(hwndDlg);
                     break;
 
                 case IDM_USER_RENAME: