Challenge: Secure User Class
Aufgabe
Swipe to start coding
Write the entire User class so that it securely manages user credentials for a login system.
- The user's password must be stored in a private field that cannot be accessed or modified directly from outside the class.
- The username must be accessible and settable publicly using a property.
- Provide a protected method that checks if a given password matches the stored password.
- Implement a constructor that initializes both the username and the password.
- Add a public method
TryLoginthat accepts an input password, checks it using the protected validation method, and prints eitherLogin successfulorLogin failedto the console. - Use the correct access modifiers for all members to ensure security and correct visibility.
- Do not include any code outside of the
Userclass except for the providedProgramclass andMainmethod.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 6
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Suggested prompts:
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you provide an example to illustrate this?
Großartig!
Completion Rate verbessert auf 4.17
Challenge: Secure User Class
Swipe um das Menü anzuzeigen
Aufgabe
Swipe to start coding
Write the entire User class so that it securely manages user credentials for a login system.
- The user's password must be stored in a private field that cannot be accessed or modified directly from outside the class.
- The username must be accessible and settable publicly using a property.
- Provide a protected method that checks if a given password matches the stored password.
- Implement a constructor that initializes both the username and the password.
- Add a public method
TryLoginthat accepts an input password, checks it using the protected validation method, and prints eitherLogin successfulorLogin failedto the console. - Use the correct access modifiers for all members to ensure security and correct visibility.
- Do not include any code outside of the
Userclass except for the providedProgramclass andMainmethod.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 6
single