PDA

View Full Version : User name and password generation



yusjoh
24th January 2018, 07:53
Hi
I have to build a QT widget using Qt Message box and Qt input dialogue that accepts a full first name and second name, then generates a user name and password. using the below criteria:
It consists of 5 lower case characters.
• The user name is created by combining the first 4 characters of the first name with the first
character of the surname.
• If the first name does not have 4 characters, more characters are taken from the surname to
make up the user name.
• If the total number of characters in the first name and the surname is less than 5 then append
sufficient number of 0s to create the username.
An initial password is generated by combining randomly selected 5 characters from the full
name of the user.
Note than no spaces are allowed in the username or password.
User input should be obtained using a QInputDialog. You can expect the full name as a
single string where each word is separated using a space. For example: Mike William
Owen. The output (username and password) should be displayed using a QMessageBox.
You need not do any verification of the user input. You can assume that the user will enter at
least two words in the QInputDialog. Assume that the first word of the input is the first name
and the last word in the name is the surname - for example, for the sample input Mike
William Owen, Mike should be read as the first name and Owen as the surname and the
generated username should be mikeo.

I only managed to do the below:
I would appreciate any help.

<code>

#include <QApplication>
#include <QInputDialog>
#include <QMessageBox>
#include <QString>
#include <QTextStream>

QTextStream cout(stdout);
QTextStream cin(stdin);

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString userFull, user1, user2;

userFull = QInputDialog::getText(0,"Please enter your full name: ", "User Name");




QMessageBox::information(0,"username: ", userFull);

//user1 = userFull.length();

//QString userinput = QInputDialog::getText(0,"Please enter your lastname: ", "User Name");
//getline(cin, user2);

//if(user1.size() < 3)

//for(int i = 0; i < user1; i++)
// getline(cin, user1.size(3));

// user1 = userName.size(3);

return a.exec();
}

</code>

Ginsengelf
24th January 2018, 12:40
Sounds like homework...
You'll have to check the docs for QString, especially methods like split() and left().

Ginsengelf

yusjoh
31st January 2018, 07:37
Hi Ginsengelf
Thank you for the info.
Would like to know how do I store individual strings in a QSstring variable, if I enter a complete string such as "My name is". Then I would like to store "My" in a separate string and so with "name" and "is", but I only enter a complete string for input using QStringList.
regards

d_stranz
31st January 2018, 17:33
but I only enter a complete string for input using QStringList.

And if you looked at the documentation for QStringList you would see that it is simply a QList of QString. And that if you store "My name is" into a QString, there are QString methods to split that into a QStringList containing the individual words.

Like you were told earlier, we don't do your homework for you. The description in your first post reads exactly like you copied and pasted it it from your homework assignment.