---
 src/user.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

--- accountsservice.orig/src/user.c
+++ accountsservice/src/user.c
@@ -1381,6 +1381,21 @@ user_change_password_mode_authorized_cb
                                 return;
                         }
 
+                        if (mode == PASSWORD_MODE_NONE) {
+                                argv[0] = "/usr/bin/gpasswd";
+                                argv[1] = "-a";
+                                argv[2] = user->user_name;
+                                argv[3] = "nopasswdlogin";
+                                argv[4] = NULL;
+
+                                error = NULL;
+                                if (!spawn_with_login_uid (context, argv, &error)) {
+                                        throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message);
+                                        g_error_free (error);
+                                        return;
+                                }
+                        }
+
                         if (mode == PASSWORD_MODE_SET_AT_LOGIN) {
                                 argv[0] = "/usr/bin/chage";
                                 argv[1] = "-d";
@@ -1428,6 +1443,23 @@ user_change_password_mode_authorized_cb
                         g_object_notify (G_OBJECT (user), "locked");
                 }
 
+                /* Remember to remove user from nopasswdlogin group if we're
+                   switching away from no-password mode */
+                if (user->password_mode == PASSWORD_MODE_NONE) {
+                        argv[0] = "/usr/bin/gpasswd";
+                        argv[1] = "-d";
+                        argv[2] = user->user_name;
+                        argv[3] = "nopasswdlogin";
+                        argv[4] = NULL;
+
+                        error = NULL;
+                        if (!spawn_with_login_uid (context, argv, &error)) {
+                                throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message);
+                                g_error_free (error);
+                                return;
+                        }
+                }
+
                 user->password_mode = mode;
 
                 g_object_notify (G_OBJECT (user), "password-mode");
@@ -1495,6 +1527,20 @@ user_change_password_authorized_cb (Daem
 
         error = NULL;
         if (!spawn_with_login_uid (context, argv, &error)) {
+                throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message);
+                g_error_free (error);
+                return;
+        }
+
+        /* Drop user from nopasswdlogin group */
+        argv[0] = "/usr/bin/gpasswd";
+        argv[1] = "-d";
+        argv[2] = user->user_name;
+        argv[3] = "nopasswdlogin";
+        argv[4] = NULL;
+
+        error = NULL;
+        if (!spawn_with_login_uid (context, argv, &error)) {
                 throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message);
                 g_error_free (error);
                 return;
