Source/NFX/IO/ConsoleUtils.cs
/// <summary>
/// Reads password from console displaying substitute characters instead of real ones
/// into a sealed SecureBuffer
/// </summary>
Reads password from console displaying substitute characters instead of real ones
into a sealed SecureBuffer
Reads password from console displaying substitute characters instead of real ones into a sealed SecureBuffer
public static SecureBuffer ReadPasswordToSecureBuffer(char substitute)
    {
      var result = new SecureBuffer();
      while (true)
      {
        char c = Console.ReadKey(true).KeyChar;
        if (Char.IsControl(c))
        {
          result.Seal();
          return result;
        }
        var buf = Encoding.UTF8.GetBytes(new char[]{ c });
        for(var i=0; i< buf.Length; i++)
          result.Push(buf[i]);
        Array.Clear(buf, 0, buf.Length);
        if (substitute != (char)0)
          Console.Write(substitute);
      }
    }
public static SecureBuffer ReadPasswordToSecureBuffer ( char substitute ) { var result = new SecureBuffer ( ) ; while ( true ) { char c = Console . ReadKey ( true ) . KeyChar ; if ( Char . IsControl ( c ) ) { result . Seal ( ) ; return result ; } var buf = Encoding . UTF8 . GetBytes ( new char [ ] { c } ) ; for ( var i = 0 ; i < buf . Length ; i ++ ) result . Push ( buf [ i ] ) ; Array . Clear ( buf , 0 , buf . Length ) ; if ( substitute != ( char ) 0 ) Console . Write ( substitute ) ; } }
Reads password from console displaying substitute characters instead of real ones
into a sealed SecureBuffer
Reads password from console displaying substitute characters instead of real ones into a sealed SecureBuffer
substitute
char