0
0
Ruby on Railsframework~20 mins

Remember me functionality in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Remember Me Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does the 'remember me' feature keep a user logged in?

In a Rails app, when a user selects 'remember me' during login, what mechanism keeps them logged in across browser sessions?

AIt stores a permanent cookie with a unique token linked to the user in the database.
BIt saves the user's password in a cookie for automatic login.
CIt uses session cookies that expire when the browser closes.
DIt stores the user's email in local storage without any token.
Attempts:
2 left
💡 Hint

Think about how Rails securely identifies a user without storing sensitive info directly in cookies.

📝 Syntax
intermediate
2:00remaining
Identify the correct way to set a permanent signed cookie in Rails

Which code snippet correctly sets a permanent signed cookie named remember_token with value token?

Acookies.signed[:remember_token] = { value: token, expires: 20.years.from_now }
Bcookies.permanent.signed[:remember_token] = token
Ccookies.permanent[:remember_token] = { signed: token }
Dcookies[:remember_token] = { value: token, expires: 1.hour.from_now }
Attempts:
2 left
💡 Hint

Remember the chaining order for setting permanent and signed cookies in Rails.

🔧 Debug
advanced
2:00remaining
Why does the 'remember me' cookie not persist after browser restart?

Given this code snippet in a Rails app, users report that the 'remember me' cookie disappears after closing the browser. What is the likely cause?

cookies[:remember_token] = user.remember_token
AThe user.remember_token is nil, so no cookie is set.
BThe cookie value is not signed, causing it to be rejected by the browser.
CThe cookie name is invalid and ignored by Rails.
DThe cookie is not set as permanent, so it expires when the browser closes.
Attempts:
2 left
💡 Hint

Think about the difference between session cookies and permanent cookies.

state_output
advanced
2:00remaining
What is the value of current_user after browser restart with 'remember me' enabled?

In a Rails app with 'remember me' implemented, after closing and reopening the browser, what will current_user be if the remember token cookie is valid?

ANil, because session data is lost after browser restart.
BAn empty user object with no attributes set.
CThe user object corresponding to the remember token cookie.
DAn error is raised because the session is missing.
Attempts:
2 left
💡 Hint

Consider how the app uses the remember token cookie to restore user state.

🧠 Conceptual
expert
2:00remaining
Why is storing the user's password in a cookie a bad idea for 'remember me'?

Why should a Rails app never store the user's password directly in a cookie for 'remember me' functionality?

ABecause cookies can be intercepted or accessed by attackers, exposing the password risks account compromise.
BBecause storing passwords in cookies causes the browser to crash.
CBecause Rails does not support storing strings in cookies.
DBecause passwords in cookies expire too quickly to be useful.
Attempts:
2 left
💡 Hint

Think about security risks of storing sensitive data on the client side.