- bool ok = initStorage(backend, settings, true /* initial setup is allowed */);
- if(ok) {
- saveBackendSettings(backend, settings);
- qWarning() << "Switched backend to:" << qPrintable(backend);
+void Core::changeUserPass(const QString &username) {
+ QTextStream out(stdout);
+ QTextStream in(stdin);
+ UserId userId = _storage->getUserId(username);
+ if(!userId.isValid()) {
+ out << "User " << username << " does not exist." << endl;
+ return;
+ }
+
+ out << "Change password for user: " << username << endl;
+
+ disableStdInEcho();
+ out << "New Password: ";
+ out.flush();
+ QString password = in.readLine().trimmed();
+ out << endl;
+ out << "Repeat Password: ";
+ out.flush();
+ QString password2 = in.readLine().trimmed();
+ out << endl;
+ enableStdInEcho();
+
+ if(password != password2) {
+ qWarning() << "Passwords don't match!";
+ return;
+ }
+ if(password.isEmpty()) {
+ qWarning() << "Password is empty!";
+ return;
+ }
+
+ if(_storage->updateUser(userId, password)) {
+ out << "Password changed successfuly!" << endl;