csharp Console.ReadPassword.cs
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Console.ReadPassword.cs相关的知识,希望对你有一定的参考价值。
[System.Diagnostics.DebuggerStepThrough]
public static string ReadPassword(char maskChar = '*')
{
var password = string.Empty;
var categories = new[] { UnicodeCategory.Control, UnicodeCategory.Format, UnicodeCategory.OtherNotAssigned, UnicodeCategory.PrivateUse, UnicodeCategory.Surrogate };
for (var key = Console.ReadKey(true); key.Key != ConsoleKey.Enter; key = Console.ReadKey(true))
{
if (!categories.Contains(char.GetUnicodeCategory(key.KeyChar)))
{
password = string.Concat(password, key.KeyChar);
Console.Write(maskChar);
}
else if (key.Key == ConsoleKey.Backspace && password.Length > 0)
{
password = password.Remove(password.Length - 1);
//Console.Write("{0} {0}", key.KeyChar); // does not handle row breaks
#region Console.Backspace();
var left = Console.CursorLeft - 1;
var top = Console.CursorTop;
if (left < 0)
{
left = Console.BufferWidth - 1;
top = top - 1;
}
Console.SetCursorPosition(left, top);
Console.WriteLine(" ");
Console.SetCursorPosition(left, top);
#endregion
}
}
Console.WriteLine();
return password;
}
以上是关于csharp Console.ReadPassword.cs的主要内容,如果未能解决你的问题,请参考以下文章
csharp 例如-CSHARP-GroupDocs.Conversion.Examples.CSharp渲染,RenderPSDImageAsPath.cs
csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs
csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs
csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs
csharp 例如-CSHARP-GroupDocs.Search.Examples.CSharp索引,AddDocumentToIndex.cs
csharp 例如-CSHARP-GroupDocs.Search.Examples.CSharp索引,AddDocumentToIndexAsynchronously.cs