// Проверяем пароль 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; }
VncView::VncView(QWidget *parent, const KUrl &url, KConfigGroup configGroup) : RemoteView(parent), m_initDone(false), m_buttonMask(0), m_repaint(false), m_quitFlag(false), m_firstPasswordTry(true), m_authenticaionCanceled(false), m_dontSendClipboard(false), m_horizontalFactor(1.0), m_verticalFactor(1.0), m_forceLocalCursor(false) { m_url = url; m_host = url.host(); m_port = url.port(); connect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)), Qt::BlockingQueuedConnection); connect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)), Qt::BlockingQueuedConnection); connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection); connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString))); m_clipboard = QApplication::clipboard(); connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged())); connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged())); #ifndef QTONLY m_hostPreferences = new VncHostPreferences(configGroup, this); #else Q_UNUSED(configGroup); #endif }
VncView::~VncView() { unpressModifiers(); // Disconnect all signals so that we don't get any more callbacks from the client thread disconnect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int))); disconnect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&))); disconnect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword())); disconnect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString))); startQuitting(); }
void CLoginDialog::OnBnClickedLoginbtn() { GetDlgItem(IDC_SAVE)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_BACK)->ShowWindow(SW_NORMAL); CString text; GetDlgItem(IDC_LoginBTN)->GetWindowText(text); SetDlgItemText(IDC_LOGTEXT,L"Log In"); if(0==text.Compare(L"Submit")){ accountSettings.SettingsSave(); m_Account.Country=((CComboBox*) GetDlgItem(IDC_COUNTRY))->GetCurSel(); std::string userPhone=countries[m_Account.Country][1]; userPhone.erase(std::find(userPhone.begin(), userPhone.end(), '+')); userPhone.erase(std::find(userPhone.begin(), userPhone.end(), '-')); CString user(m_Account.username); user.Replace((CString)userPhone.c_str(),NULL); GetDlgItemText(IDC_PHONE,m_Account.username); CT2CA ansistring (m_Account.username); userPhone.append(ansistring); m_Account.username=(CString)userPhone.c_str(); GetDlgItemText(IDC_PASSWORD,m_Account.password); accountSettings.accountId = accountId; //m_Account.rememberPassword=1; accountSettings.AccountSave(accountId, &m_Account); //accountSettings.SettingsSave(); if(requestPassword()){ accountSettings.account = m_Account; EndDialog(IDOK); } else SetDlgItemText(IDC_LOGTEXT,L"Wrong username or password"); } else{ caption="Log In"; SetWindowText(caption); SetDlgItemText(IDC_LoginBTN,L"Submit"); GetDlgItem(IDC_EMAIL)->ShowWindow(SW_HIDE); GetDlgItem(IDC_LOGTEXT)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_LOGO)->ShowWindow(SW_HIDE); GetDlgItem(IDC_COUNTRY)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_PHONE)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_CountryCode)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_PASSWORD)->ShowWindow(SW_NORMAL); GetDlgItem(IDC_Register)->ShowWindow(SW_HIDE); ((CButton*) GetDlgItem(IDC_SAVE))->SetCheck(BST_CHECKED); m_Account.rememberPassword=BST_CHECKED; } }
// Пройти аутентификацию int passAuthentication(struct Connection *connection) { switch (connection->auth.status) { case LOGIN_REQUEST: requestLogin(connection); break; case LOGIN_CHECK: checkLogin(connection); break; case PASSWORD_REQUEST: requestPassword(connection); break; case PASSWORD_CHECK: checkPassword(connection); break; default: fprintf(stderr, "Error: wrong authentication status of connectionfd %d\n", connection->connectionfd); return -1; } return 0; }
// Проверяем логин int checkLogin(struct Connection *connection) { char *login = NULL; if (readNonBlock(connection->connectionfd, &login, 0) == -1) { fprintf(stderr, "Error: receiving login from connection %d\n", connection->connectionfd); return -1; } connection->pair = getPair(login); if (connection->pair == NULL) { if (sendMsg(connection->connectionfd, "Wrong login, try again\n") == -1) { fprintf(stderr, "Error: sending wrong login msg\n"); return -1; } requestLogin(connection); } else { connection->auth.status = PASSWORD_REQUEST; requestPassword(connection); } free(login); return 0; }