我正在尝试在qt中实现登录页面并陷入一个奇怪的问题。我想检查两种类型的密码。一个是常规密码,第二个是masterpassword。当使用者输入错误密码5次时,他必须输入主密码,如果他输入3个错误密码,则显示错误。
我已编写代码,但面临一个我无法解决的问题。这是我的登录代码:
d = df.groupby('number').name.apply(list).to_dict()
df = pd.DataFrame({k : pd.Series(v)
for k, v in d.items()}).add_prefix('num').fillna('')
print(df)
num1 num2 num3
0 Bob David Jane
1 Mike Josh
2 Emily
我只想在第一个函数中的尝试等于5时调用第二个函数。但是在5个循环之后,我的代码调用第二个函数,但它然后同时运行第一个函数和第二个函数。谁能告诉我我做错了什么?我试图将函数组合在一起,并试图在第一个函数中使用第二个函数作为嵌套循环,但即使我将它设置在“if循环”条件内,它仍然会调用整个函数:
void FormLogin::OnLogin()
{
QString password = passLineEdit->text();
// Checking if username or password is empty
if (password.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "Password field is empty!");
} else if (password == "pass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong password!!! Only %1 attempt(s) left!").arg(4-attempt));
attempt++;
if (attempt == 5){
QMessageBox::information(this, tr("Warning!"), QString("The device is locked due to too many failed attempts. Please enter the master password to unlock the device now."));
connect(loginButton, SIGNAL(clicked()), this, SLOT(OnMasterLogin()));
return;}
}
}
void FormLogin::OnMasterLogin()
{
QString mpassword = passLineEdit->text();
// Checking if username or password is empty
if (mpassword.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "MPassword field is empty!");
} else if (mpassword == "masterpass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong mpassword!!! Only %1 attempt(s) left!").arg(2-master_attempt));
master_attempt++;
if (master_attempt == 3){
QMessageBox::information(this, tr("Warning!"), QString("The device is permanently locked due to too many failed attempts. Please contact the device manufacturer."));}}
}
使用以下代码调用第一个函数:
void FormLogin::OnLogin()
{
QString password = passLineEdit->text();
// Checking if username or password is empty
if (password.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "Password field is empty!");
} else if (password == "pass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong password!!! Only %1 attempt(s) left!").arg(4-attempt));
attempt++;
if (attempt == 5){
QMessageBox::information(this, tr("Warning!"), QString("The device is locked due to too many failed attempts. Please enter the master password to unlock the device now."));
QString mpassword = passLineEdit->text();
// Checking if username or password is empty
if (mpassword.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "MPassword field is empty!");
} else if (mpassword == "masterpass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong mpassword!!! Only %1 attempt(s) left!").arg(2-master_attempt));
master_attempt++;
if (master_attempt == 3){
QMessageBox::information(this, tr("Warning!"), QString("The device is permanently locked due to too many failed attempts. Please contact the device manufacturer."));}}}
}
}
任何建议都受到高度赞赏。
答案 0 :(得分:1)
我假设您已经将loginButton :: clicked()连接到FormLogin :: OnLogin()。在该方法中,在五次尝试时,您添加另一个连接到FormLogin :: OnMasterLogin(),但您仍保留原始连接。如果当前处于“主登录”模式,请使用disconnect()或向FormLogin :: OnLogin()添加逻辑以进行挽救。
答案 1 :(得分:0)
您可以在调用第一个函数之前添加if (attempt < 5)
条件。如果达到5次尝试,这应该防止进入第一个功能。