예제 #1
0
// Проверяем пароль
int checkPassword(struct Connection *connection) {
    char *password = NULL;
    if (readNonBlock(connection->connectionfd, &password, 0) == -1) {
        fprintf(stderr, "Error: receiving password from connection %d\n", connection->connectionfd);
        return -1;
    }
    if (verifyPassword(connection->pair, password) == -1) {
        if (connection->auth.attempts == MAX_PASSWORD_ATTEMPTS) {
            fprintf(stderr, "Many password enter attempts for user: %s\n", connection->pair->login);
            if (sendMsg(connection->connectionfd, "Too many password enter attempts\n") == -1) {
                fprintf(stderr, "Error: sending wrong too many attempts msg\n");
                return -1;
            }
            closeConnection(connection);
            return -1;
        }
        if (sendMsg(connection->connectionfd, "Wrong password, try again\n\n") == -1) {
            fprintf(stderr, "Error: sending wrong password msg\n");
            return -1;
        }
        connection->auth.attempts++;
        requestPassword(connection);
    } else {
        if (sendMsg(connection->connectionfd, "Authentication complete!\n") == -1) {
            fprintf(stderr, "Error: sending password msg\n");
            return -1;
        }
        connection->auth.status = AUTHENTICATED;
    }
    free(password);
    return 0;
}
예제 #2
0
void Platform::clientInfoUpdate()
{
	char tmpBuf[BUF_LEN];
	cout << "logId:";
	string logId;
	cin >> tmpBuf;
	logId = tmpBuf;

	cout << "password:"******"1.bind bank card 2.change password 0.nothing" << endl;
	cin >> n;
	if (n == 1)
	{
		//第三部分
		char tmpBuf[BUF_LEN];
		cout << "bankName:";
		string bankName;
		cin >> tmpBuf;
		bankName = tmpBuf;

		cout << "cardNum:";
		string cardNum;
		cin >> tmpBuf;
		cardNum = tmpBuf;

		cout << "bank card password:"******"ICBC\1!00000006\1!123\1!10"
		string sendMsg1 = bankName + "\1!" + cardNum + "\1!" + bankCardPassword + "\1!0\0";
		char sendMsg[MSG_MAX_LEN];
		strcpy(sendMsg, sendMsg1.c_str());
		string res = this->ec_connect(this->argc, this->argv, sendMsg);
		if (res != "YES")
		{
			cout << "银行卡信息验证失败" << endl;
			return;
		}

		createCardRecord(logId, bankName, cardNum);
	}