App interfaces Extend the Password property in PasswordManager

Hi,

I am at the last step in the App interfaces challenge.
I got a strange Exception:

Process is terminating due to StackOverflowException.

I cannot to understand this error.

My code is here...

namespace SavingInterface
{
  class PasswordManager : IDisplayable, IResetable 
  {
    // fields:
    string password;
    
    // properties:
    private string Password { 
      get {
        return this.Password;
      } 
      set {
        if (value.Length >=8) {
          this.Password = value;
        }
      }
    }

    public bool Hidden
    { get; private set; }

    public char HeaderSymbol { get; }

    // constructor:
    public PasswordManager(string password, bool hidden)
    {
      Password = password;
      Hidden = hidden;
      this.HeaderSymbol = '$';
    }

    // methods:
    public void Display() {
      Console.WriteLine("Password");
      string result = new String(this.HeaderSymbol, 8);
      Console.WriteLine(result);
      Console.WriteLine(this.Hidden ? "******" : this.Password);
    }

    public void Reset() {
      this.Password = "";
      this.Hidden = false;
    }

    public bool ChangePassword(string current, string newPassword) {
      if (String.Equals(current, this.Password)) {
        this.Password = newPassword;
        return true;
      } else {
        return false;
      }
    }
  }
}

Hi Lendoo - the problem here is accidental recursion.

This code is calling itself:

set
 {
     if (value.Length >=8) 
  {
          this.Password = value;
  }
}

Specifically, this line is setting the Password property inside the setter for the Password property:

this.Password = value;

It looks like you already defined a backing field for this, so simply change the property code to get and set the backing field instead of the property itself, and you’ll be good to go:

 // fields:
    string password;
    
    // properties:
    private string Password { 
      get {
        return this.password;
      } 
      set {
        if (value.Length >=8) {
          this.password = value;
        }
      }
    }

Actually, this way you don’t need the “this” syntax either, although there’s no harm in it.