5. Implementing Key-Value Pair Databases and Authentication Workflows

User Interface Design and Screen Flow

  • User Interface Components of the Login Screen:

    • Labels: Two text label elements positioned on the screen to indicate required credentials.

    • Text Inputs: Two distinct text input fields designated for entering data (specifically the username and password).

    • Login Button: A functional button element programmed to trigger authentication and screen transitions upon being clicked.

  • Screen State Architecture:

    • Login Screen: The primary entry window containing the labels, text input boxes, and the submission button where the user inputs their details.

    • Success Screen: The window displayed upon successful credential validation, presenting the user with confirmation text such as: "You logged in. Welcome to the app."

    • Failure Screen: The window displayed when validation fails, showing an error prompt: "Your username and password incorrect. Please try again."

  • Data Access Panel:

    • Clicking the data button within the interface opens various accessible tables covering diverse pre-existing datasets such as geography, politics, and science.

Data Management and Key-Value Pair Concepts

  • Table Classifications:

    • Data Table: Standard tabular format for storing and querying general data records.

    • Key-Value Pair Table: A computer science data structure where information is stored in strict pairs consisting of a unique identifier (the key) and its associated data (the value).

  • Key-Value Pair Mechanics:

    • Providing a unique key to the table returns the specific value associated with that key.

    • Theoretical Example:

      • Table Name: names

      • Key: name

      • Value: Bob

      • Lookup Operation: Querying names.name accesses the key and outputs Bob.

  • Syntax and Formatting Rules:

    • Keys: Must be entered directly into the table without quotation marks or speech marks.

    • Values: String values must be enclosed within speech marks (quotation marks).

Implementation and Authentication Logic

  • Initial Conceptual Setup:

    • Two blank variables are defined at the start of the program: username and password.

    • A student identifier format is introduced as a value example, such as 15xyzed@saintgeorge'swaybridgeokay.com.

    • A sample password value is established as bob 123.

  • Event Handling and Input Retrieval:

    • An event listener monitors when the login button is clicked.

    • The program extracts the user-submitted string from the username input field and assigns it to the username variable.

    • The program extracts the user-submitted string from the password input field and assigns it to the password variable.

  • Corrected Authentication Architecture:

    • Database Key-Value Setup:

      • Key: The username string (e.g., 15XYzed or X15XY zed).

      • Value: The matching password string (e.g., bob 123).

    • Verification Workflow:

      • The system takes the username value entered into the screen's text input.

      • The key-value block queries the database table using that entered username as the lookup key.

      • The table finds the key and returns its corresponding stored value (the legitimate password).

      • Conditional Evaluation:

        • The program checks whether the password entered by the user matches the value returned by the database lookup.

        • Example Outcome 1 (Mismatch): If the user types 15XYzed for the username and bib 123 for the password, the database returns bob 123. Because bib 123 does not equal bob 123, the condition evaluates to false, executing the else branch and calling set screen to navigate to the error screen.

        • Example Outcome 2 (Match): If the entered password exactly equals the stored value bob 123, the condition evaluates to true, directing the application to the logged-in success screen.

Secondary Use Cases and Academic Requirements

  • Informational Database Lookups:

    • Key-value pairs can be deployed for general knowledge queries beyond user authentication.

    • Automotive Example:

      • Key: Vehicle name or model identifier, such as Porsche 911 (or Maserati).

      • Value: An extensive string of descriptive text containing detailed facts and specifications regarding the Porsche 911.

      • Execution: A query passing the vehicle identifier retrieves the entire text block, which is then mapped to a display component on screen.

  • Assessment and Grading Criteria:

    • Implementing a database with key-value structures earns higher marks on the project grading card compared to omitting database integration.

Questions and Discussion

  • User Interface Element Clarification:

    • Question: What are the input areas on the login screen called?

    • Response: After suggestions of "labels", "text box", "input text", and "input boxes", it is confirmed that they are formally designated as "text inputs".

  • Classroom Focus and Evaluation:

    • Prompt: Distractions involving swinging on chairs and laughing during the explanation.

    • Response: Attention and focus are strictly required because the key-value material and variable implementations directly contribute to student marks.

  • Application to Sign-Up Workflows:

    • Question: Would that be like a sign-up screen?

    • Response: Implementation depends entirely on system design. For a sign-up screen design, the interface can collect the entered username and password and store those exact values directly into the key-value table.