Exemplo n.º 1
0
void Database::init()
{
   std::map<string, string> insertParamMap0 = { {"id", "1"}, 
                                                {"username", "admin"},
                                                {"password", encryptPassword("admin")} };
   std::map<string, string> insertParamMap1 = { {"id", "2"}, 
                                                {"username", "anonymous"},
                                                {"password", encryptPassword("anonymous")} };
   std::map<string, string> insertParamMap2 = { {"id", "3"}, 
                                                {"username", "charles"},
                                                {"password", encryptPassword("charles")} };
   std::map<string, string> insertParamMap3 = { {"id", "4"}, 
                                                {"username", "davey"},
                                                {"password", encryptPassword("davey")} };

   std::map<string, string> selectParamMap = {  {"id", "1"}, {"username", "Paul"} };
   std::map<string, string> updateParamMap = {  {"username", "davey"}, {"password", "dddd"} };

   create();
   insert("user", insertParamMap0);
   insert("user", insertParamMap1);
   insert("user", insertParamMap2);
   insert("user", insertParamMap3);
   //select("user", selectParamMap);

   // init user's root working directory
   if(findALL("user"))
   {
      vector< map<string ,string> > myresultMapVector;
      getResult(myresultMapVector);
      for (vector< map<string ,string> >::iterator iter=myresultMapVector.begin(); iter!=myresultMapVector.end(); ++iter)
      {
         string dirString(ROOTDIR);
         dirString += (*iter)["USERNAME"];
         DIR* d = opendir(dirString.c_str());
         if(d)
         {  
            fprintf(stderr, "Already exists: %s\n",  dirString.c_str());
            closedir(d);
         }else if(mkdir(dirString.c_str(), 0777) == -1)
         {
            char buf[MAXLINE];
            fprintf(stdout, "Error(%s): %s\n", dirString.c_str(), strerror_r(errno, buf, MAXLINE));
         } else {
            fprintf(stdout, "Directory created: %s\n", dirString.c_str());
         }

         //traverseFiles(dirString);
      }
   }

   

   //update("user", "2", updateParamMap);
   //find("user", "2");
}
/*!
 *
 * @param username
 * @param password
 * @return
 */
QMap<QString, Customer>* Database::loginAsAdmin(QString username, QString password){
    unsigned* digest = encryptPassword(password);
    QMap<QString, Customer>* customerMap = new QMap<QString, Customer>();

    if(validateAdminLogin(username, digest)){
        sqlite3_stmt* stmt;
        int rc = sqlite3_prepare_v2(connection, "SELECT c_name FROM ics_customers", -1, &stmt, NULL);
        rc = sqlite3_step(stmt);

        while(rc != SQLITE_DONE){
            QString name = QString(static_cast<const char*>(sqlite3_column_blob(stmt, 0)));

            customerMap->insert(name, Customer(connection, name));

            rc = sqlite3_step(stmt);
        }
    }
    else{
        ostringstream ex;
        ex << "Invalid login by " << username.toStdString();
        throw new InvalidLoginException(ex.str().c_str());
    }

    return customerMap;
}
Exemplo n.º 3
0
/**
 * Encrypt a password for storing in the MaxScale.cnf file
 *
 * @param argc	Argument count
 * @param argv	Argument vector
 */
int
main(int argc, char **argv)
{
	char	*enc, *pw;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: %s <password>\n", argv[0]);
		exit(1);
	}
	
	pw = calloc(81,sizeof(char));

	if(pw == NULL){
		fprintf(stderr, "Error: cannot allocate enough memory.");
		exit(1);
	}

	strncpy(pw,argv[1],80);

	if ((enc = encryptPassword(pw)) != NULL){
		printf("%s\n", enc);
	}else{
		fprintf(stderr, "Failed to encode the password\n");
	}

	free(pw);
	return 0;
}
/*!
 *
 * @param username
 * @param password
 * @param customer
 */
void Database::registerCustomer(QString username, QString password, QString customer){
    unsigned* digest = encryptPassword(password);

    if(checkKeyCollision("ics_customer_logins", "cl_username", username.toStdString()) ||
       checkKeyCollision("ics_customer_logins", "cl_customer", customer.toStdString())){
        throw new KeyCollisionException("Username already exists or customer already has an account.");
    }

    ostringstream sqlCmmd;
    sqlCmmd << "INSERT INTO ics_customer_logins (cl_customer, cl_password_part_one, "
            << "cl_password_part_two, cl_password_part_three, cl_password_part_four, "
            << "cl_password_part_five, cl_username) VALUES ('"
            << customer.toStdString()  << "', "
            << digest[0] << ", "
            << digest[1] << ", "
            << digest[2] << ", "
            << digest[3] << ", "
            << digest[4] << ", '"
            << username.toStdString() << "')";

    char* errMsg;
    sqlite3_exec(connection, sqlCmmd.str().c_str(), NULL, 0, &errMsg);
    if(errMsg != NULL){
        cerr << errMsg << endl;
    }
}
Exemplo n.º 5
0
/**
 * Encrypt a password for storing in the MaxScale.cnf file
 *
 * @param argc	Argument count
 * @param argv	Argument vector
 */
int
main(int argc, char **argv)
{
	char	*enc, *pw;
	int	arg_count = 6;
	char	*home;
    char** arg_vector;
    int rval = 0;

	if (argc != 3)
	{
		fprintf(stderr, "Usage: %s <file> <password>\n", argv[0]);
		return 1;
	}

    arg_vector = malloc(sizeof(char*)*(arg_count + 1));

	if(arg_vector == NULL)
	{
	    fprintf(stderr,"Error: Memory allocation failed.\n");
	    return 1;
	}

	arg_vector[0] = strdup("logmanager");
	arg_vector[1] = strdup("-j");
	arg_vector[2] = strdup("/var/log/maxscale");

	arg_vector[3] = "-o";
	arg_vector[4] = "-l";
	arg_vector[5] = "LOGFILE_ERROR";
	arg_vector[6] = NULL;
	skygw_logmanager_init(arg_count,arg_vector);
	free(arg_vector[2]);
	free(arg_vector);
	
	pw = calloc(81,sizeof(char));

	if(pw == NULL){
		fprintf(stderr, "Error: cannot allocate enough memory.");
		return 1;
	}

	strncpy(pw,argv[2],80);

	if ((enc = encryptPassword(argv[1],pw)) != NULL){
		printf("%s\n", enc);
	}else{
		fprintf(stderr, "Failed to encode the password\n");
		rval = 1;
	}

	free(pw);
	skygw_log_sync_all();
	skygw_logmanager_done();
	return rval;
}
Exemplo n.º 6
0
bool GJContext::SignIn(LPCTSTR username,LPCTSTR password,CLoginFrame *loginFrame)
{
	StopRecv();
	this->m_pLoginFrame=loginFrame;
	bool bOk=true;
	JID *nSelf=new JID();
	if(!nSelf)
	{
		bOk=false;
	}else if(!nSelf->setServer(m_Server)||!nSelf->setUsername(utf8enc(username)))
	{
		bOk=false;
	}else { 
		if(m_pClient) 
			m_pClient->disconnect();  
		m_pClient=new Client(*nSelf,encryptPassword(utf8enc(password)),m_Port);  
		m_pVCardMgr=new VCardManager(m_pClient);
		if(!m_pClient)
			bOk=false;
		else
		{
			m_pClient->registerConnectionListener(this);
			m_pClient->registerIqHandler(this,0);
			m_pClient->registerMessageHandler(this);
			m_pClient->rosterManager()->registerRosterListener(this,false);
			bOk= m_pClient->connect(false);

		}
	}
	if(!bOk&&nSelf) 
		delete nSelf;
	else 
	{
		if(m_pSelf)
			delete m_pSelf;
		m_pSelf=nSelf; 
		StartRecv();
	}

	return bOk;
}
/*!
 *
 * @param username
 * @param password
 * @return
 */
Customer* Database::loginAsCustomer(QString username, QString password){
    unsigned* digest = encryptPassword(password);
    Customer* customer;

    if(validateCustomerLogin(username, digest)){
        ostringstream sqlCmmd;
        sqlCmmd << "SELECT cl_customer FROM ics_customer_logins WHERE cl_username = '******'";
        sqlite3_stmt* stmt;
        sqlite3_prepare_v2(connection, sqlCmmd.str().c_str(), -1, &stmt, NULL);
        sqlite3_step(stmt);
        customer = new Customer(connection, QString(static_cast<const char*>(sqlite3_column_blob(stmt, 0))));
    }
    else{
        ostringstream ex;
        ex << "Invalid login by " << username.toStdString();
        throw new InvalidLoginException(ex.str().c_str());
    }

    return customer;
}
/*!
 *
 * @param username
 * @param password
 */
void Database::registerAdmin(QString username, QString password){
    unsigned* digest = encryptPassword(password);

    if(checkKeyCollision("ics_admin_logins", "al_admin", username.toStdString())){
        throw new KeyCollisionException("Admin username already exists.");
    }

    ostringstream sqlCmmd;
    sqlCmmd << "INSERT INTO ics_admin_logins (al_admin, al_password_part_one, "
            << "al_password_part_two, al_password_part_three, al_password_part_four, "
            << "al_password_part_five) VALUES ('"
            << username.toStdString()  << "', "
            << digest[0] << ", "
            << digest[1] << ", "
            << digest[2] << ", "
            << digest[3] << ", "
            << digest[4] << ")";

    char* errMsg;
    sqlite3_exec(connection, sqlCmmd.str().c_str(), NULL, 0, &errMsg);
    if(errMsg != NULL){
        cerr << errMsg << endl;
    }
}
Exemplo n.º 9
0
void LLSavedLoginEntry::setPassword(const std::string& value)
{
	mEntry.insert("password", encryptPassword(value));
}
Exemplo n.º 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;   
  }
}
Exemplo n.º 11
0
int main()
{
	std::string encrypt = encryptPassword("password");
	return 0;
}