public void changePassword(String newPassword) {} // Change the current user\'s
ID: 3754476 • Letter: P
Question
public void changePassword(String newPassword) {} // Change the current user's password
public void logout() {} // Log out the current user
public void setCurrentUser(String username) {} // A mutator you can use to write tests
// without simulating user input
Both changePassword and logout operate on the currentUser, so they do not take a username as a parameter. changePassword should modify the currentUser’s password to be the given newPassword. logout should set the currentUser to null.
The setCurrentUser method should not be used by any other method in AccessControl, but may be very useful for writing test methods. You must implement it even if you do not use it in any test methods. (We may use it when testing your code.)
Explanation / Answer
public void changePassword(String newPassword) {
this.userPassword = newPassword; // set the received password as the new password to change the user password
}
public void logout() {
this.username = null; // set the current user name is null to Log out the current user
}
public void setCurrentUser(String username) {
this.username = username; // set the received user name as the current username
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.