Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 4 MCQsAuthentication and Database Integration
What is the main purpose of authentication in a web application?
Not quite. Try another option.
Answer: To verify a user's identity
Authentication confirms that a user is who they claim to be.
Question 2 of 60 · Authentication Concepts · Easy
Which credential is commonly used with a username during authentication?
Not quite. Try another option.
Answer: A password
A username and password are commonly used together to authenticate a user.
Question 3 of 60 · Session Management · Easy
What does a session commonly store after a user logs in?
Not quite. Try another option.
Answer: The user's login state
A session helps the application remember that the user has already logged in.
Question 4 of 60 · Session Management · Easy
What usually happens to a user's session when they log out?
Not quite. Try another option.
Answer: It is destroyed or invalidated
Logging out normally ends or invalidates the active session.
Question 5 of 60 · Protected Routes · Easy
What is a protected route?
Not quite. Try another option.
Answer: A route limited to authorized users
A protected route checks access before allowing a user to view or use it.
Question 6 of 60 · Protected Routes · Easy
Where is an unauthenticated user commonly sent when opening a protected route?
Not quite. Try another option.
Answer: To the login page
Applications commonly redirect unauthenticated users to a login page.
Question 7 of 60 · Authorization · Easy
What does authorization determine?
Not quite. Try another option.
Answer: What an authenticated user may do
Authorization decides which resources and actions a user is permitted to access.
Question 8 of 60 · Authorization · Easy
Which check is an example of authorization?
Not quite. Try another option.
Answer: Checking permission to delete a post
Authorization checks whether a user has permission to perform a specific action.
Question 9 of 60 · Role-based Access Control · Easy
In role-based access control, permissions are primarily assigned to what?
Not quite. Try another option.
Answer: Roles
RBAC assigns permissions to roles, which are then assigned to users.
Question 10 of 60 · Role-based Access Control · Easy
Which role would commonly have permission to manage all user accounts?
Not quite. Try another option.
Answer: Administrator
An administrator role commonly has broad permissions, including user management.
Question 11 of 60 · ORM Basics · Easy
What does ORM stand for?
Not quite. Try another option.
Answer: Object-Relational Mapping
ORM stands for Object-Relational Mapping.
Question 12 of 60 · ORM Basics · Easy
What does an ORM help developers do?
Not quite. Try another option.
Answer: Work with database data as objects
An ORM maps database records to objects used by application code.
Question 13 of 60 · Database Connectivity · Easy
What is required for an application to connect to a database?
Not quite. Try another option.
Answer: A database connection string
A connection string provides details the application needs to reach the database.
Question 14 of 60 · Database Connectivity · Easy
Which value is commonly included in database connection settings?
Not quite. Try another option.
Answer: Database host
The database host identifies the server where the database is running.
Question 15 of 60 · CRUD Operations · Easy
What does the letter C represent in CRUD?
Not quite. Try another option.
Answer: Create
In CRUD, C stands for Create, which means adding new data.
Question 16 of 60 · CRUD Operations · Easy
Which CRUD operation changes an existing database record?
Not quite. Try another option.
Answer: Update
The Update operation modifies data that already exists.
Question 17 of 60 · CRUD Operations · Easy
Which CRUD operation retrieves stored data?
Not quite. Try another option.
Answer: Read
The Read operation retrieves existing data from a database.
Question 18 of 60 · Data Validation · Easy
Why is user input validated before it is stored?
Not quite. Try another option.
Answer: To ensure it meets expected rules
Validation checks that input has the required type, format, and constraints.
Question 19 of 60 · Data Validation · Easy
Which is a basic validation rule for a required email field?
Not quite. Try another option.
Answer: It must not be empty
A required field must contain a value before the form can be accepted.
Question 20 of 60 · Environment Variables · Easy
Why are environment variables commonly used in web applications?
Not quite. Try another option.
Answer: To store configuration outside source code
Environment variables keep settings such as database URLs and secret keys outside the source code.
Question 21 of 60 · Authentication Concepts · Medium
A web application stores user passwords for login verification. Which approach provides the best protection if the database is exposed?
Not quite. Try another option.
Answer: Store passwords as salted cryptographic hashes
Salted hashing is one-way and makes precomputed password attacks more difficult. Passwords should not be stored in plain text or reversible form.
Question 22 of 60 · Authentication Concepts · Medium
Why should a server regenerate a session identifier after a user successfully logs in?
Not quite. Try another option.
Answer: To prevent session fixation attacks
Regenerating the session identifier prevents an attacker from forcing a known session ID on a user and later reusing it after authentication.
Question 23 of 60 · Session Management · Medium
A session cookie should not be accessible through client-side JavaScript because of which cookie attribute?
Not quite. Try another option.
Answer: HttpOnly
The HttpOnly attribute prevents JavaScript from reading the cookie, reducing the impact of many cross-site scripting attacks.
Question 24 of 60 · Session Management · Medium
An application must ensure that a session cookie is sent only over HTTPS connections. Which cookie setting addresses this requirement?
Not quite. Try another option.
Answer: Secure
The Secure attribute instructs the browser to send the cookie only over HTTPS connections.
Question 25 of 60 · Session Management · Medium
What is the primary purpose of an idle session timeout?
Not quite. Try another option.
Answer: To invalidate inactive sessions after a period
An idle timeout reduces the risk of unauthorized access when a user leaves an authenticated session unused.
Question 26 of 60 · Protected Routes · Medium
A request to /dashboard is received without a valid authenticated session. What should protected-route middleware typically do?
Not quite. Try another option.
Answer: Redirect or return an authentication error
Protected-route middleware must stop unauthenticated requests and either redirect the user to login or return an appropriate 401 Unauthorized response.
Question 27 of 60 · Protected Routes · Medium
A frontend hides an administrator link, but the corresponding API endpoint has no server-side authentication check. What is the main security problem?
Not quite. Try another option.
Answer: The API can still be called directly
Hiding a user-interface element does not protect an endpoint. Authorization checks must be enforced on the server for every sensitive request.
Question 28 of 60 · Authorization · Medium
A logged-in user requests another user's private profile by changing the user ID in the URL. Which authorization check is needed?
Not quite. Try another option.
Answer: Check whether the requester owns the resource
Authentication confirms who the requester is, while authorization must determine whether that user may access the specific profile.
Question 29 of 60 · Authorization · Medium
Which response status is most appropriate when a user is authenticated but lacks permission to delete a resource?
Not quite. Try another option.
Answer: 403 Forbidden
403 Forbidden indicates that the server understood the request but refuses to authorize the authenticated user to perform it.
Question 30 of 60 · Role-based Access Control · Medium
In a role-based access control system, a user has the role editor, which permits updating articles but not deleting them. What should happen when the user sends a delete request?
Not quite. Try another option.
Answer: The request should be denied by a permission check
RBAC maps roles to permissions. Since editor lacks the delete permission, the server should reject the delete operation.
Question 31 of 60 · Role-based Access Control · Medium
What is a key advantage of assigning permissions to roles instead of configuring permissions separately for every user?
Not quite. Try another option.
Answer: It simplifies consistent permission management
Roles centralize permission rules, making access policies easier to apply, review, and update across many users.
Question 32 of 60 · ORM Basics · Medium
In an ORM, a User class is mapped to a database table. What does an instance of the class usually represent?
Not quite. Try another option.
Answer: A row in the mapped table
ORMs commonly represent table rows as objects, with object properties corresponding to columns.
Question 33 of 60 · ORM Basics · Medium
What is the main purpose of an ORM migration?
Not quite. Try another option.
Answer: To change the database schema in a tracked way
Migrations record and apply schema changes such as creating tables, adding columns, or modifying indexes in a repeatable manner.
Question 34 of 60 · Database Connectivity · Medium
An application is deployed to production and fails because it cannot connect to the database. Which configuration should be checked first?
Not quite. Try another option.
Answer: The database connection string and credentials
Connection failures commonly result from an incorrect host, port, database name, username, password, or network setting.
Question 35 of 60 · Database Connectivity · Medium
Why should a web application use a connection pool for frequent database access?
Not quite. Try another option.
Answer: It reuses connections and reduces setup overhead
Connection pools maintain reusable database connections, improving performance and limiting the overhead of repeatedly opening new connections.
Question 36 of 60 · CRUD Operations · Medium
Which operation best represents updating a user's email address in a database?
Not quite. Try another option.
Answer: Updating an existing record
Changing a value in an existing user's record is an update operation, corresponding to the update part of CRUD.
Question 37 of 60 · CRUD Operations · Medium
A user submits a form to create a new blog post. Which practice best reduces SQL injection risk when inserting the data?
Not quite. Try another option.
Answer: Use parameterized queries or ORM binding
Parameterized queries and ORM binding keep user input separate from executable SQL syntax, reducing SQL injection risk.
Question 38 of 60 · Data Validation · Medium
A registration endpoint receives an email field that contains an empty string. What is the best validation behavior?
Not quite. Try another option.
Answer: Reject it with a clear validation error
Required fields should be validated before processing. Returning a clear error helps the client correct invalid input and protects data quality.
Question 39 of 60 · Data Validation · Medium
Why should validation be performed on the server even when the frontend already validates the form?
Not quite. Try another option.
Answer: Clients can bypass or modify frontend checks
Frontend validation improves user experience, but the server must enforce rules because clients are not trusted and can send arbitrary requests.
Question 40 of 60 · Environment Variables · Medium
Which value is most appropriate to store in an environment variable rather than directly in source code?
Not quite. Try another option.
Answer: A database password
Environment variables keep deployment-specific and sensitive configuration, such as database passwords, outside the source code repository.
Question 41 of 60 · Authentication Concepts · Hard
A web application stores passwords using a fast hash function with a unique salt per user. An attacker obtains the password table and can evaluate billions of hashes per second. Which change most directly improves resistance to offline cracking?
Not quite. Try another option.
Answer: Use a memory-hard password hashing function
Memory-hard functions such as Argon2id make large-scale guessing expensive in both computation and memory, which is specifically effective against offline password cracking.
Question 42 of 60 · Authentication Concepts · Hard
A login endpoint returns the same HTTP status, response body structure, and approximate timing for an unknown email and an incorrect password. What security property is this design primarily intended to provide?
Not quite. Try another option.
Answer: Resistance to account enumeration
Uniform responses and timing reduce the ability of attackers to determine whether an account exists based on login behavior.
Question 43 of 60 · Session Management · Hard
A user logs in successfully, but the server keeps the anonymous session identifier and merely adds an authenticated flag. Which remediation is most important?
Not quite. Try another option.
Answer: Rotate the session identifier after authentication
Rotating the identifier after privilege elevation prevents session fixation, where an attacker preselects or obtains a session ID that the victim later authenticates.
Question 44 of 60 · Session Management · Hard
A server-side session store uses a sliding idle timeout. Two requests from the same session arrive concurrently: one is valid at time , while the other was sent before the session expired but reaches the server afterward. Which design best prevents stale-request resurrection?
Not quite. Try another option.
Answer: Use atomic compare-and-update expiration checks
Atomic validation and update operations prevent concurrent requests from extending an already expired session because of race conditions.
Question 45 of 60 · Protected Routes · Hard
A single-page application hides an admin link for non-admin users, but its API endpoint only checks whether a request has a valid login session. What is the primary flaw?
Not quite. Try another option.
Answer: The API trusts presentation logic for authorization
Client-side route hiding is not a security boundary. The API must independently authenticate the request and authorize the requested operation.
Question 46 of 60 · Protected Routes · Hard
A protected route checks authentication in middleware, then redirects unauthenticated users to a login page. An attacker supplies a URL containing an external destination as the return parameter. Which control is required?
Not quite. Try another option.
Answer: Permit only relative internal return paths
Allowing arbitrary destinations can create an open redirect. The return target should be validated as a safe internal path or selected from an allowlist.
Question 47 of 60 · Authorization · Hard
An endpoint permits a user to fetch /orders/4821 after checking that the user is logged in, but it does not compare the order's owner ID with the requester. What vulnerability remains?
Not quite. Try another option.
Answer: Broken object-level authorization
Authentication establishes who the requester is, but object-level authorization must establish whether that requester may access order 4821.
Question 48 of 60 · Authorization · Hard
A document update service first verifies that a user may edit a document and then performs the update using only the document ID. The document can be moved between tenants by another process between these operations. Which solution best addresses the issue?
Not quite. Try another option.
Answer: Perform authorization and mutation in one transaction
Combining the authorization predicate with the mutation in an appropriate transaction prevents time-of-check-to-time-of-use races.
Question 49 of 60 · Role-based Access Control · Hard
A user has both viewer and editor roles. The application denies access if any assigned role lacks permission, even when another role grants it. Which RBAC evaluation model is usually intended instead?
Not quite. Try another option.
Answer: Grant if at least one applicable role permits
Common additive RBAC evaluates permissions as the union of applicable role grants, while explicit deny rules, if supported, must be defined separately.
Question 50 of 60 · Role-based Access Control · Hard
An administrator changes a user's role from admin to support, but existing access tokens contain the old role claim and remain valid for one hour. Which mitigation most directly limits stale privilege?
Not quite. Try another option.
Answer: Validate revocation or privilege version server-side
Server-side revocation checks or a privilege-version comparison can invalidate tokens issued before the role change instead of trusting stale embedded claims.
Question 51 of 60 · ORM Basics · Hard
An ORM loads 1,000 posts and lazily fetches each author's record while rendering them. The database receives one query for posts and 1,000 author queries. What is the most appropriate correction when all authors are needed?
Not quite. Try another option.
Answer: Use eager loading or a batched relation query
Eager loading or batching reduces the N+1 query pattern by retrieving related authors in a small number of queries.
Question 52 of 60 · ORM Basics · Hard
An ORM model accepts a request body containing email, displayName, and isAdmin, and uses a generic update method. A client changes isAdmin despite lacking permission. Which ORM-level control is most relevant?
Not quite. Try another option.
Answer: Apply an allowlist for mass-assigned fields
Mass-assignment protection ensures that only explicitly permitted attributes, such as email and displayName, can be updated from client input.
Question 53 of 60 · Database Connectivity · Hard
A production service opens a new database connection for every request and occasionally exhausts the database connection limit under load. Which architecture is most appropriate?
Not quite. Try another option.
Answer: Use a bounded connection pool with release handling
A bounded pool reuses connections while limiting concurrent database usage. Connections must be released even when requests fail.
Question 54 of 60 · Database Connectivity · Hard
A database transaction updates an inventory row, but a second transaction can read the intermediate value before the first transaction commits. Which database property is missing or inadequately configured?
Not quite. Try another option.
Answer: Isolation
Isolation controls how visible one transaction's intermediate changes are to concurrent transactions. Dirty reads indicate insufficient isolation.
Question 55 of 60 · CRUD Operations · Hard
An API implements PUT /users/7 by updating only fields present in the request and leaving all other fields unchanged. A client omits a field expecting it to be cleared. Which design correction is most accurate?
Not quite. Try another option.
Answer: Document the endpoint as partial update semantics
Updating only supplied fields is PATCH-like behavior. The API should use or document partial-update semantics, while full replacement should define omitted fields explicitly.
Question 56 of 60 · CRUD Operations · Hard
Two clients read a product with version 12. Both submit updates, and the second update silently overwrites the first. Which implementation provides optimistic concurrency control?
Not quite. Try another option.
Answer: Update only where the ID and version both match
An update such as WHERE id = ? AND version = 12 detects a stale client when no row is affected; the successful update then increments the version.
Question 57 of 60 · Data Validation · Hard
A registration validator checks that an email has a valid format, but the database later rejects it because the email column is unique. Which validation strategy is correct?
Not quite. Try another option.
Answer: Keep the unique constraint and handle conflicts
Application checks are vulnerable to races. The database constraint is authoritative, and the API should translate a uniqueness violation into a suitable response.
Question 58 of 60 · Data Validation · Hard
A server validates a request's JSON structure but accepts a string such as "999999999999999999999" for an integer amount, allowing inconsistent coercion across services. What is the strongest fix?
Not quite. Try another option.
Answer: Use strict schemas with bounded numeric constraints
Strict schema validation should reject incorrect types and enforce safe ranges before business logic or persistence, avoiding inconsistent coercion and overflow.
Question 59 of 60 · Environment Variables · Hard
A deployment reads DATABASE_URL successfully, but a secret containing a dollar sign and spaces is truncated or altered by the shell. Which practice best prevents this configuration error?
Not quite. Try another option.
Answer: Quote values according to the deployment environment
Shells and deployment tools interpret spaces, dollar signs, and other characters specially. Correct quoting or secret-manager injection preserves the exact value.
Question 60 of 60 · Environment Variables · Hard
An application falls back to a development signing key when AUTH_SECRET is missing. In production, a deployment typo therefore starts successfully but issues forgeable tokens. Which design is safest?
Not quite. Try another option.
Answer: Fail startup when required secrets are absent
Required security-critical configuration should be validated at startup. Failing closed prevents the service from operating with a known or weak default secret.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of INT257 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of INT257 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.