Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Secure User Class | Class Design and Encapsulation
C# OOP Class Construction Drills

bookChallenge: 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 TryLogin that accepts an input password, checks it using the protected validation method, and prints either Login successful or Login failed to the console.
  • Use the correct access modifiers for all members to ensure security and correct visibility.
  • Do not include any code outside of the User class except for the provided Program class and Main method.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

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?

close

bookChallenge: 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 TryLogin that accepts an input password, checks it using the protected validation method, and prints either Login successful or Login failed to the console.
  • Use the correct access modifiers for all members to ensure security and correct visibility.
  • Do not include any code outside of the User class except for the provided Program class and Main method.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
single

single

some-alt