1

I'm trying to enter a special character, but the app still displays a message «Wrong password!» If anyone knows what my mistake is, I will be glad if you point it out. Thanks in advance.

Special character i use: ☺ (U+263A)

Console.WriteLine("Enter a password:");

var pass = Console.ReadLine();

var key = '\u263a'.ToString();

while (pass != key)
{
    if (pass != key)
    {
        Console.WriteLine("Wrong password!");
        pass = Console.ReadLine();    
    }
    else
    {
        break;
    }
}
Console.WriteLine("Info: test 123");

Console.ReadKey();

upd. Screenshot 1: variable "pass" in debug

Screenshot 2: variable "key" in debug

Euxinus
  • 23
  • 5

2 Answers2

0

try to decode it to UTF-8

Console.WriteLine("Enter a password:");

Console.InputEncoding = System.Text.Encoding.UTF8;
var pass = Console.ReadLine();

var key = '\u263a'.ToString();

while (pass != key)
{
    if (pass != key)
    {
        Console.WriteLine("Wrong password!");
        Console.InputEncoding = System.Text.Encoding.UTF8;
        pass = Console.ReadLine();    
    }
    else
    {
        break;
    }
}
Console.WriteLine("Info: test 123");

Console.ReadKey();
  • Unfortunately, this method did not work. By the way, I noticed the variable "pass" in debug: After entering a character in the console, it accepts the string "\u0001" instead of "\u263a" – Euxinus Jan 03 '22 at 13:01
  • Probably `System.Text.Encoding.Unicode` instead. – Phil1970 Jan 03 '22 at 14:17
0

Just put this

Console.InputEncoding = Encoding.GetEncoding(1200);

at the top of the program

Ledrake
  • 114
  • 10