RPG::RPG(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RPG)
{
    ui->setupUi(this);

    connect(ui->lowerCheckBox,SIGNAL(clicked(bool)),this,SLOT(lowerCaseEnabler(bool)));
    connect(ui->upperCheckBox,SIGNAL(clicked(bool)),this,SLOT(upperCaseEnabler(bool)));
    connect(ui->numberCheckBox,SIGNAL(clicked(bool)),this,SLOT(digitEnabler(bool)));
    connect(ui->specialCheckBox,SIGNAL(clicked(bool)),this,SLOT(specialCharacterEnabler(bool)));

    connect(ui->passwordButton,SIGNAL(clicked()),this,SLOT(generatePassword()));

    ui->lengthSpinBox->setValue(20);
    ui->passwordLineEdit->setReadOnly(true);
    setFixedSize(QSize(sizeHint()));

    ui->passwordLineEdit->setStyleSheet(
                "color:rgb(127,0,63);"
                "background-color:rgb(255,255,241);"
                "selection-color:white;"
                "selection-background-color:rgb(191,31,127);"
                "border:2px groove gray;"
                "border-radius:10px;"
                "padding:2px 4px;");


}
void test_generate_base85_password () {
    char* password = generatePassword(12, BASE85);
    int i=0;
    for(i=0;i<getStringLength(password);i++)
        CU_ASSERT_TRUE(containsChar(base85,password[i]));
    
    CU_ASSERT_EQUAL(getStringLength(password),12);
}
void test_generate_base64_password () {
    char* password = generatePassword(12, BASE64);
    int i=0;
    for(i=0;i<getStringLength(password);i++)
        CU_ASSERT_TRUE(containsChar(base64,password[i]));
    printf("len: %d", getStringLength(password));
    CU_ASSERT_EQUAL(getStringLength(password),12);
        
}
示例#4
0
/**
* \brief Function to change VISHNU user password
* \fn int resetPassword(UMS_Data::User user, std::string sendmailScriptPath)
* \param user The user data structure
* \param sendmailScriptPath The path to the script for sending emails
* \return raises an exception on error
*/
int
UserServer::resetPassword(UMS_Data::User& user, std::string sendmailScriptPath) {
  std::string sqlResetPwd;
  std::string sqlUpdatePwdState;
  std::string passwordCrypted;
  std::string pwd;


  //If the user exists
  if (exist()) {
    //if the user is an admin
    if (isAdmin()) {
      //if the user whose password will be reset exists
      if (getAttribut("where userid='"+user.getUserId()+"'").size() != 0) {
        //generation of a new password
        pwd = generatePassword(user.getUserId(), user.getUserId());
        user.setPassword(pwd.substr(0,PASSWORD_MAX_SIZE));

        //to get the password encryptes
        passwordCrypted = vishnu::cryptPassword(user.getUserId(), user.getPassword());

        //The sql code to reset the password
        sqlResetPwd = "UPDATE users SET pwd='"+passwordCrypted+"' where "
        "userid='"+user.getUserId()+"';";
        //sql code to update the passwordstate
        sqlUpdatePwdState = "UPDATE users SET passwordstate=0 "
        "where userid='"+user.getUserId()+"' and pwd='"+passwordCrypted+"';";
        //To append the previous sql codes
        sqlResetPwd.append(sqlUpdatePwdState);
        //Execution of the sql code on the database
        mdatabaseVishnu->process( sqlResetPwd.c_str());
        //to get the email adress of the user
        std::string email = getAttribut("where userid='"+user.getUserId()+"'", "email");
        user.setEmail(email);
        //Send email
        std::string emailBody = getMailContent(user, false);
        sendMailToUser(user, emailBody, "Vishnu message: password reset", sendmailScriptPath);
      } // End if the user whose password will be reset exists
      else {
        UMSVishnuException e (ERRCODE_UNKNOWN_USERID, "You must use a global VISHNU identifier");
        throw e;
      }
    } //END if the user is an admin
    else {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }
  } //END if the user exists
  else {
    UMSVishnuException e (ERRCODE_UNKNOWN_USER);
    throw e;
  }
  return 0;
}//END: resetPassword(UMS_Data::User user)
示例#5
0
bool Form::generatePassword(const QString &matric)
{
    LoginDialog login(1, this);
    if(login.exec() == QDialog::Accepted){
        if(login.isSame()){
            DatabaseHandler db;
            if(db){
                if(!db.addNewPassword({matric, login.getPassword()})){
                    QMessageBox::critical(nullptr, "Password", "An error occurred", QMessageBox::Ok);
                    generatePassword(matric);
                } else {
                    return true;
                }
            }
        } else {
            QMessageBox::critical(nullptr, "Password", "Passwords do not match", QMessageBox::Ok);
            generatePassword(matric);
        }
    } else {
        generatePassword(matric);
    }
    return true;
}
void PasswordDialog::on_buttonBox_accepted()
{
    int count = ui->countInput->value();
    bool capital = ui->capitalCheck->isChecked();
    bool small = ui->smallCheck->isChecked();
    bool digit = ui->digitCheck->isChecked();
    if(!capital && !small && !digit) {
        QMessageBox::warning(this, tr("Operation Error"),  tr("Can't generate password without capital letters, small letters and digits"));
        return;
    }

    this->accept();
    emit generatePassword(count, capital, small, digit);
}
示例#7
0
/**
* \brief Function to add a new VISHNU user
* \fn int add(UMS_Data::User*& user, int vishnuId)
* \param user The user data structure
* \param vishnuId The identifier of the vishnu instance
* \param sendmailScriptPath The path to the script for sending emails
* \return raises an exception on error
*/
int
UserServer::add(UMS_Data::User*& user, int vishnuId, std::string sendmailScriptPath) {
  std::string pwd;
  std::string sqlUpdate = "update users set ";

  std::string idUserGenerated;
  std::string passwordCrypted;
  std::string formatiduser;

  if (exist()) {
    if (isAdmin()) {

      //Generation of password
      pwd = generatePassword(user->getLastname(), user->getFirstname());
      user->setPassword(pwd.substr(0,PASSWORD_MAX_SIZE));

      //Generation of userid
      idUserGenerated = vishnu::getObjectId(vishnuId,
                                            "formatiduser",
                                            USER,
                                            user->getLastname());
      user->setUserId(idUserGenerated);
      //To get the password encrypted
      passwordCrypted = vishnu::cryptPassword(user->getUserId(), user->getPassword());

      // If there only one field reserved by getObjectId
      if (getAttribut("where userid='"+user->getUserId()+"'","count(numuserid)") == "1") {

        //To active the user status
        user->setStatus(ACTIVE_STATUS);

        sqlUpdate+="vishnu_vishnuid="+convertToString(vishnuId)+", ";
        sqlUpdate+="pwd='"+passwordCrypted+"', ";
        sqlUpdate+="firstname='"+user->getFirstname()+"', ";
        sqlUpdate+="lastname='"+user->getLastname()+"', ";
        sqlUpdate+="privilege="+convertToString(user->getPrivilege())+", ";
        sqlUpdate+="email='"+user->getEmail()+"', ";
        sqlUpdate+="passwordstate=0, ";
        sqlUpdate+="status="+convertToString(user->getStatus())+" ";
        sqlUpdate+="where userid='"+user->getUserId()+"';";
        mdatabaseVishnu->process(sqlUpdate);


        //Send email
        std::string emailBody = getMailContent(*user, true);
        sendMailToUser(*user, emailBody, "Vishnu message: user created", sendmailScriptPath);

      }// END If the user to add exists
      else {
        UMSVishnuException e (ERRCODE_USERID_EXISTING);
        throw e;
      }
    } //END if the user is an admin
    else {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }
  } //END if the user exists
  else {
    UMSVishnuException e (ERRCODE_UNKNOWN_USER);
    throw e;
  }
  return 0;
}//END: add(UMS_Data::User*& user)
示例#8
0
string UserServices::resetPassword(int userID){

	User *update = getUser(userID);
	update->_password = generatePassword();
	return update->_password;
}
示例#9
0
void Form::acceptForm()
{
    QStringList studentList, studentList2;
    if(ui->lineAppNumber->text() == "" || ui->lineSurname->text() == ""
            || ui->lineOthernames->text() == "" || ui->lineExamNumber->text() == ""
            || ui->lineAddress->text() == "")
    {
        QMessageBox::critical(this, "Error", "You cannot leave column(s) blankly",
                              QMessageBox::Ok);
    } else {
        if(ui->lineExamNumber->text() != ""){
            if(ui->listWidget->count() < 5){
                QMessageBox::critical(this, tr("Error!"), tr("You must have at least 5 O'Level subjects"),
                                      QMessageBox::Ok);
                viewDialog();
                return;
            }
        }
        if(ui->checkBoxTwoSittings->isChecked()){
            if(ui->lineExamNumber2->text() == "" || ui->listWidget_2->count() < 5){
                QMessageBox::critical(this, windowTitle(), tr("Make sure you fill in the exam year"
                                                              " and at least 5 subjects are chosen"),
                                      QMessageBox::Ok);
                return;
            } else {
                int allStudentsCount = ui->listWidget_2->count();
                for(int i = 0; i != allStudentsCount; ++i)
                {
                    studentList2.append(ui->listWidget_2->item(i)->text());
                }
                studentList2.insert(studentList2.begin(), ui->lineExamNumber2->text());
            }
        }

        QStringList databaseList;
        databaseList << ui->lineAppNumber->text().trimmed() << ui->lineSurname->text().trimmed()
                     << ui->lineOthernames->text().trimmed() << ui->lineAddress->text().trimmed()
                     << ui->comboBoxSex->currentText() << ui->comboBoxLevel->currentText()
                     << ui->comboBoxSession->currentText() << ui->comboBoxMaritalStatus->currentText()
                     << ui->comboBoxReligion->currentText() << ui->comboBoxState->currentText()
                     << ui->comboBoxDepartment->currentText()
                     << ui->dateDOB->text() << ui->lineExamNumber->text().trimmed()
                     << ui->lineExamNumber2->text().trimmed() << ui->comboBoxExamType->currentText()
                     << ui->comboBoxExamType2->currentText() << ui->spinBoxYear->text()
                     << ui->spinBoxYear2->text();

        int allStudentsCounter = ui->listWidget->count();
        for(int i = 0; i != allStudentsCounter; ++i)
        {
            studentList.append(ui->listWidget->item(i)->text());
        }
        studentList.insert(studentList.begin(), ui->lineExamNumber->text());

        if(database){
            if(database.addNewStudent(databaseList, studentList, studentList2)
                    && generatePassword(databaseList[0]))
            {
                switch(QMessageBox::information(this, "Sucess", "New Record Saved Successfully! Add more?",
                                         QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
                {
                case QMessageBox::No:
                    this->close();
                    break;
                case QMessageBox::Yes:
                    clearWindow();
                    break;
                default:
                    this->close();
                    break;
                }
            } else {
                QMessageBox::information(this, tr("Error"),
                    tr("There was an error trying to save the record into the database. Please"
                       " check all inputs"), QMessageBox::Ok);
            }
        }
    }
}
示例#10
0
void bluetoothProcessReply(SoftwareSerial* bluetoothSerial, char *inputString)
{  
  char encryptedPassword[2 * PASSWORD_SIZE]; //make them more local
  char shortEncryptedPassword[PASSWORD_SIZE];
  char password[PASSWORD_SIZE];
  char message[MESSAGE_SIZE];
  
  memset(encryptedPassword, 0, 2 * PASSWORD_SIZE);
  memset(shortEncryptedPassword, 0, PASSWORD_SIZE);
  memset(password, 0, PASSWORD_SIZE);
  memset(message, 0, MESSAGE_SIZE);
  
  int typeCommand = getTypeCommand(inputString);
  
  switch (typeCommand)
  {
    case '0' + 1:
      { // add new entry
        getLastMessage(inputString, password);
        if (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword)) {
          generateBluetoothAddMessage(inputString, encryptedPassword, strlen(password), message);
          setMessageReceiver(Phone);
          storeInDataBuffer(message);
          memset(message, '\0', MESSAGE_SIZE);
          generateStoredInBuffer(message);
          sendToBluetooth(bluetoothSerial, message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 2: //retrive password
    case '0' + 13: //retrive note 
      {
        getLastMessage(inputString, encryptedPassword);
        generateShortPassword(encryptedPassword, shortEncryptedPassword);
        byte l = getPasswordLength(inputString);
        if (decryptPassword((unsigned char*)shortEncryptedPassword, (unsigned char*)key, PASSWORD_CHUNCKS, l, (unsigned char*)password)) {
          generateSerialRetriveInfo(password, message);
          setMessageReceiver(Pc);
          storeInDataBuffer(message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 5:
      { // get from message and store the hash value and close connection
        char hash[HASH_SIZE]; //input = "5:hash_value\n
        memset(hash, '\0', HASH_SIZE);
        getLastMessage(inputString, hash);
        writeHash(hash);
      }
      break;
    case '0' + 6:
      { //read hash from EERPOM and send back to bluetooth
        char hash[HASH_SIZE]; //input = 6:\n
        memset(hash, '\0', HASH_SIZE);
        readHash(hash);
        generateBluetoothRetrieveHash(hash, HASH_SIZE, message); //message = 6:hash_value\n
        storeInDataBuffer(message);
        setMessageReceiver(Phone);
        setEnableBluetoothOperations(true);
      }
      break;
     case '0' + 4:
      {
        char lastTimeUsed[LAST_TIME_USED_SIZE];
        memset(lastTimeUsed, '\0', LAST_TIME_USED_SIZE);
        readLastTimeUsed(lastTimeUsed);
        generateBluetoothLastTimeUsed(lastTimeUsed, LAST_TIME_USED_SIZE, message);
        //Serial.print(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;
    case '0' + 10:
      {
        char lastTimeUsed[LAST_TIME_USED_SIZE];
        memset(lastTimeUsed, '\0', LAST_TIME_USED_SIZE);
        getLastMessage(inputString, lastTimeUsed);
        writeLastTimeUsed(lastTimeUsed);
      }
      break;
    
    case '0' + 7:
      { // generate password
        if ((generatePassword(inputString, password, PASSWORD_CHUNCKS)) &&
           (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword))) {
            generateBluetoothAddMessage(inputString, encryptedPassword, strlen(password), message);
            setMessageReceiver(Phone);
            storeInDataBuffer(message);
            memset(message, '\0', MESSAGE_SIZE);
            generateStoredInBuffer(message);
            sendToBluetooth(bluetoothSerial, message);
        } else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 8:
      { // get the salt
        char salt[SALT_SIZE];
        memset(salt, '\0', SALT_SIZE);
        getLastMessage(inputString, salt);
        readKey(key, KEY_SIZE, salt);
      }
      break;
    case '0' + 9:
      { // is alive message
        generateIsAliveMessage(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;
    case '0' + 12:
      { //add note
        getLastMessage(inputString, password);//password = note text
        if (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword)) {
          generateBluetoothAddNote(inputString, encryptedPassword, strlen(password), message);
          setMessageReceiver(Phone);
          storeInDataBuffer(message);
          
          generateStoredInBuffer(message);
          sendToBluetooth(bluetoothSerial, message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    default:
      {
        generateErrorMessage(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;   
  }
}