How do I validate char's entered into textbox by user

0 favourites
  • 2 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Hello all, I'm designing a game to help build cyber security awareness. The game is called Password Wizard and is intended to help players learn how to create a strong password.

    The Game:

    Players must help a wizard defend his castle from the evil Undead Knight and his minions by following onscreen steps to create a password spell before they reach the castle.

    The steps for making the password are as follows:

    Step 1: Have user enter a short phrase that's familiar to them/easy for them to remember

    Step 2: Have them make the phrase into an acronym

    Step 3: Have them capitalize every other letter

    Step 4: Have them replace all the letter A's with the symbol

    Step 5: Have them replace all the letter E's with the number 3

    Step 6: Have them replace all the letter I's with the symbol !

    and so on... which would eventually result in a very strong password.

    The part I need help with is validating the entries made by the user. For example, when they are asked to enter the acronymized version of their phrase, I need the game to be able acronymize the original phrase and compare it to what they entered. If it is correct then let the user move on to the next step.

    Similarly for the other steps, when they replace all the letter A's with the symbol, I want the game to swap out all the A's for symbols in the text and compare it to what they entered. If it is correct then let the user move on to the next step.

    I know how to write a function to carry out the acronymization in C++, but I am having difficulty translating this into Construct 2. This is the C++ code I have:

    #include <iostream>

    #include <string>

    #include <cctype>

    using namespace std;

    string acronym(string str);

    int main()

    {

    string str;

    while (true)

    {

    cout << "\nPlease enter a string: ";

    getline(cin, str);

    if (str == "")

    {

    break;

    }

    cout << "\n\nThe acronym is \"" << acronym(str) << "\"" << "\n";

    }

    system("PAUSE");

    return 0;

    }

    string acronym(string str)

    {

    string phrase = "";

    phrase = str[0];

    for (int i = 0; i < str.length(); i++)

    {

    if (str == ' ')

    {

    phrase += str[i+1];

    }

    }

    return phrase;

    }

    -----------------------------------------------------------------------------------------------------------------------------------------

    This is my attempt at translating it to Construct 2:

    UserPhrase and Acronym are both text type global variables initialized at the top.

    The text object that is being set to Acronym is just my way of verifying the output to the screen after I type in the phrase.

    Here is the current result of this attempt:

    I'm not sure where my logic is going wrong, also to reiterate, I am new to Construct 2 and I'm not very verse in all its functionality. If anyone can shed some light on my situation it would be greatly appreciated. I really want to see these game thru and let kids at the high school nearby test it out and enjoy it.

    Best regards.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I applaud your efforts here. Cybersecurity is one of the most misunderstood fields by the broader public. I have never found a way to make it sexy though, lol.

    My best efforts so far have resulted in a "draw a password" system.

    As far as your validation efforts go, look at "regex". Regex is one of the most demonically useful tools out there.

    Although, I can't see to find a good online tool for testing regex in C++.

    try: https://www.myregextester.com/

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)