void AddUserDlg::slotCheckPwd() { ui.infoLabel->setText(""); if (ui.canLoginCheckBox->isChecked()) { if (!checkPwd()) { return; } } if (true) { char pwdStr[512] =""; char userName[128]=""; if( ui.userNameEdit->text().trimmed().length() < 1 ) { ui.infoLabel->setText(i18n("Please input user name.")); ui.userNameEdit->selectAll(); return; } pwdStr[0] = '\0'; userName[0] = '\0'; snprintf(pwdStr,sizeof(pwdStr),"%s",qPrintable(ui.PwdEdit->text()) ); snprintf(userName,sizeof(userName),"%s",qPrintable(ui.userNameEdit->text().trimmed() ) ); void *auxerror; int pwdErrValue = 0; int pwdValue = pwquality_check (get_pwq (), pwdStr, NULL, userName,&auxerror); if( pwdValue < 0 ) { pwdErrValue = 0; QString setStr = pwdErrorStr(pwdValue,&pwdErrValue); if( pwdErrValue > 0 ) { int i = ui.PwdEdit->text().length(); if( i < 0 ) { i = 1; } pwdErrValue = 2*i; if( pwdErrValue >100 ) { pwdErrValue = 100; } ui.pwdProgressBar->setValue(pwdErrValue); } else { ui.infoLabel->setText(setStr); ui.PwdEdit->selectAll(); ui.pwdProgressBar->setValue(0); return; } } else { ui.pwdProgressBar->setValue(pwdValue); } } if( ui.verifyPwdEdit->text() != ui.PwdEdit->text() ){ ui.infoLabel->setText(i18n("Passwords do not match.")); return; } }
void AddUserDlg::slotAddUser() { if (!_am) { close(); } QString userName = ui.userNameEdit->text().trimmed(); if (userName.isEmpty()) { QMessageBox::warning(this, "warning", i18n("Please input user name.")); return; } if (ui.canLoginCheckBox->isChecked()) { if (!checkPwd()) { return; } } if (ui.PwdEdit->text().isEmpty()) { QMessageBox::warning(this, "warning", i18n("Please input account password.")); return; } if (ui.verifyPwdEdit->text().isEmpty()) { QMessageBox::warning(this, "warning", i18n("Please input verify password.")); return; } if (ui.PwdEdit->text() != ui.verifyPwdEdit->text()) { QMessageBox::warning(this, "warning", i18n("Passwords do not match.")); return; } QtAccountsService::UserAccount *user = _am->findUserByName(userName); if (user) { QMessageBox::warning(this, "warning", i18n("User already exists")); return; } QtAccountsService::UserAccount::AccountType accType = ui.canLoginCheckBox->isChecked() ? QtAccountsService::UserAccount::AdministratorAccountType : QtAccountsService::UserAccount::StandardAccountType; bool ret = _am->createUser(userName,ui.realNameEdit->text().trimmed(),accType); if (!ret) { QMessageBox::warning(this, "warning",i18n("Failed to add user.")); close(); return; } connect(_am, SIGNAL(userAdded(UserAccount *)), this, SLOT(slotUserAdded(UserAccount*))); }
bool AddPwd(EntityManager *entityManager, int16_t userId) { bool pass = true; char userName[EXP_MAX_USER_NAME]; snprintf(userName, sizeof(userName), USER_NAME_FMT, userId); pass = createAndAddPwd(entityManager, userName); if (pass) { pass = checkPwd(entityManager, userName); } return pass; }
void loop(){ if (delayInactif.check()) { stateProgram = NORMAL; clearBuffers(); Serial.println("raz"); } char key = keypad.getKey(); if (key != NO_KEY){ delayInactif.reset(); delay(100); switch (key){ case 'A': case 'B': case 'C': case 'D': break; case '#': // reset pwd if (stateProgram == NORMAL) { chaineReset(&pwd_buffer); } else { modifyPwd(key); } break; case '*': // check pwd if (stateProgram == NORMAL) { checkPwd(); chaineReset(&pwd_buffer); } else { modifyPwd(key); } break; default: //append to buffer if (stateProgram == NORMAL) { chaineAppend(key, &pwd_buffer); chainePrint(pwd_buffer); } else { modifyPwd(key); } // end of switch } } }
int _tmain() { while(nCount >= 0) { if(nCount == 3) { tprintf(_T("plz input name:\r\n")); scanf("%64s",szInName); tprintf(_T("plz input password:\r\n")); scanf("%64s",szInPwd); } else { //因为checkName的返回值和checkPwd的返回值相加后正好是 0 1 2 3,分别代表都错,名对密错,名错密对,名对密对 switch(nResult) { case 0: reInput(0);//重新输入用户名和密码 break; case 1: reInput(1);//重新输入密码 break; case 2: reInput(2);//重新输入用户名; break; case 3: tprintf(_T("bingo!you are clever!\r\n")); nCount = 0;//将控制循环次数标记改为1,用于退出循环 break; default: reInput(0);//重新输入用户名和密码 break; } } nResult = checkName(szInName) + checkPwd(szInPwd); //因为checkName的返回值和checkPwd的返回值相加后正好是 0 1 2 3,分别代表都错,名对密错,名错密对,名对密对 switch(nResult) { case 0: tprintf(_T("name and password error!\r\n")); break; case 1: tprintf(_T("password error!\r\n")); break; case 2: tprintf(_T("name error!\r\n")); break; case 3: tprintf(_T("bingo!you are clever!\r\n")); nCount = 0;//将控制循环次数标记改为1,用于退出循环 break; default: reInput(0);//重新输入用户名和密码 break; } nCount--; needexit(); } return 0; }
int main() { int newpwd, newpwda; // 更改密码时,用户两次输入的新密码 char sourcefile[30], // 加密/解密的文件名 targetFile[30], // 解密/加密后要保存的文件名 secretKey[21], // 文件加密的密钥 action; // 要进行的操作 // 操作前先校验使用密码 if(!checkPwd(1)) { printf("Sorry,check failed!please press any key to quit...\n"); getch();//吃掉按键不回显 exit(1); } // 密码校验成功,进入程序 while(1) { system("cls"); // 清屏 printMenu(); // 显示菜单 scanf("%c",&action); // 输入要执行的操作 fflush(stdin); // 清空stdin缓冲区 system("cls"); switch(action) { case 'z': printf("Bye!"); exit(0); break; case 'a': while(1) { printf("Enter the name of sourcefile(route):\n"); scanf("%s", sourcefile); printf("Enter secretkey:\n"); //密钥是用户自己定义的,可以随意给需要加密的文件添加密钥 scanf("%s", secretKey); printf("Enter the name of targetfile(route):\n"); //给加密后的文件命名,并保存 scanf("%s",targetFile); if( encryptFile(sourcefile, secretKey, targetFile) ) { printf("Congratulation!,encrypt [%s] successfully,save in[%s].\n", sourcefile, targetFile); } if(redo() == 'a') // 继续加密文件 { system("cls"); } else // 回到主菜单 { break; } } break; case 'b': while(1) { printf("Enter the name of sourcefile(route):\n"); scanf("%s",sourcefile); printf("Enter secretkey:\n"); scanf("%s",secretKey); printf("Enter the name of targetfile(route):\n"); //对解密的文件系统又可以提供保存路径 scanf("%s", targetFile); if( encryptFile(sourcefile, secretKey, targetFile) ) { printf("Congratulation!,decrypt [%s] successfully,save in[%s].\n", sourcefile, targetFile); } if(redo() == 'a') // 继续解密文件 { system("cls"); } else { break; // 回到主菜单 } } break; case 'c': while(1) { if(!checkPwd(2)) { printf("Sorry,check failed!please press any key to quit...\n"); getch(); exit(0); } printf("Please enter new password\n"); scanf("%d",&newpwd); printf("Please enter new password again\n"); scanf("%d",&newpwda); if(newpwd==newpwda) // 两次输入密码相同才成功 { password = newpwd; printf("Congrarulation!Change password successfully!\n"); } else { printf("Sorry,twice enter is not same,change failed!\n"); } if(redo() == 'a') // 继续修改密码 { system("cls"); } else // 回到主菜单 { break; } } break; default: printf("No such choice,please press any key back to menu...\n"); getch(); } } return 0; }