1 Star 0 Fork 3

xingwei-liu/dde-control-center

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-add-password-reminder.patch 4.63 KB
一键复制 编辑 原始数据 按行查看 历史
From 6c4050e695babbe68b321e5669be280fe6c3b0c6 Mon Sep 17 00:00:00 2001
From: xingwei-liu <liuxingwei@uniontech.com>
Date: Wed, 5 Jan 2022 09:27:08 +0800
Subject: [PATCH] add password reminder
---
src/frame/modules/accounts/accountsworker.cpp | 80 ++++---------------
.../modules/accounts/modifypasswdpage.cpp | 6 +-
2 files changed, 18 insertions(+), 68 deletions(-)
diff --git a/src/frame/modules/accounts/accountsworker.cpp b/src/frame/modules/accounts/accountsworker.cpp
index cf80a16..7f11f21 100644
--- a/src/frame/modules/accounts/accountsworker.cpp
+++ b/src/frame/modules/accounts/accountsworker.cpp
@@ -53,65 +53,6 @@ const QString DisplayManagerService("org.freedesktop.DisplayManager");
const QString AutoLoginVisable = "auto-login-visable";
const QString NoPasswordVisable = "nopasswd-login-visable";
-const QString ModifyPassword =
-R"(#!/usr/bin/expect
-
-# oldpassword: the current password
-# userpass: the new password
-# repeatpass: repeat the new password
-set oldpassword [lindex $argv 0]
-set userpass [lindex $argv 1]
-set repeatpass [lindex $argv 2]
-
-# spawn the passwd command process
-spawn passwd
-
-# Verify the 'Current password'
-expect "Current password: "
-send -- "$oldpassword\r"
-
-# Type the 'New password'
-expect "New password:"
-send -- "$userpass\r"
-
-# current password verify
-send_user "\rpassword right\r"
-
-# Verify the 'Retype password'
-expect "Retype*"
-send -- "$repeatpass\r"
-
-# Type the 'New password'
-expect "New password:"
-send -- "$userpass\r"
-
-# Verify the 'Retype password'
-expect "Retype*"
-send -- "$repeatpass\r"
-
-expect eof
-)";
-
-const QString ModifyNoPassword =
-R"(#!/usr/bin/expect
-
-# userpass: the new password
-# repeatpass: repeat the new password
-set userpass [lindex $argv 0]
-set repeatpass [lindex $argv 1]
-
-# spawn the passwd command process
-spawn passwd
-
-# Type the 'New password'
-expect "New password:"
-send -- "$userpass\r"
-
-# Verify the 'Retype password'
-expect "Retype*"
-send -- "$repeatpass\r"
-expect eof
-)";
AccountsWorker::AccountsWorker(UserModel *userList, QObject *parent)
: QObject(parent)
@@ -386,16 +327,23 @@ void AccountsWorker::setPassword(User *user, const QString &oldpwd, const QStrin
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LC_ALL", "C");
process.setProcessEnvironment(env);
+ process.setProcessChannelMode(QProcess::MergedChannels);
- QString cmd = user->passwordStatus() == NO_PASSWORD ? ModifyNoPassword : ModifyPassword;
+ process.start("/bin/bash", QStringList() << "-c" << QString("passwd"));
+ if (user->passwordStatus() == NO_PASSWORD) {
+ process.write(QString("%1\n%2\n").arg(passwd).arg(repeatPasswd).toLatin1());
+ }else {
+ process.write(QString("%1\n%2\n%3").arg(oldpwd).arg(passwd).arg(repeatPasswd).toLatin1());
+ }
+ //QString cmd = user->passwordStatus() == NO_PASSWORD ? ModifyNoPassword : ModifyPassword;
- QStringList args = QStringList() << "-f" << "-";
- if (user->passwordStatus() != NO_PASSWORD) args.append(oldpwd);
- args.append(passwd);
- args.append(repeatPasswd);
+ //QStringList args = QStringList() << "-f" << "-";
+ //if (user->passwordStatus() != NO_PASSWORD) args.append(oldpwd);
+ //args.append(passwd);
+ //args.append(repeatPasswd);
- process.start("/bin/expect", args);
- process.write(cmd.toLatin1());
+ //process.start("/bin/expect", args);
+ //process.write(cmd.toLatin1());
process.closeWriteChannel();
process.waitForFinished();
diff --git a/src/frame/window/modules/accounts/modifypasswdpage.cpp b/src/frame/window/modules/accounts/modifypasswdpage.cpp
index 9b2137f..e1e63cb 100644
--- a/src/frame/window/modules/accounts/modifypasswdpage.cpp
+++ b/src/frame/window/modules/accounts/modifypasswdpage.cpp
@@ -166,8 +166,10 @@ void ModifyPasswdPage::onPasswordChangeFinished(const int exitCode, const QStrin
Q_UNUSED(exitCode)
PwqualityManager::ERROR_TYPE error = PwqualityManager::instance()->verifyPassword(m_curUser->name(),
m_newPasswordEdit->lineEdit()->text());
- if (errorTxt.contains("password unchanged")) {
- if (!errorTxt.contains("password right", Qt::CaseInsensitive)) {
+ //if (errorTxt.contains("password unchanged")) {
+ if (exitCode != 0) {
+ if (errorTxt.startsWith("Current password: Current Password: passwd:", Qt::CaseInsensitive)) {
+ //if (!errorTxt.contains("password right", Qt::CaseInsensitive)) {
m_oldPasswordEdit->setAlert(true);
m_oldPasswordEdit->showAlertMessage(tr("Wrong password"));
return;
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xingwei-liu/dde-control-center.git
git@gitee.com:xingwei-liu/dde-control-center.git
xingwei-liu
dde-control-center
dde-control-center
a8

搜索帮助