using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
bool a = true;
while(a)
{
Console.Write("请输入账号:");
string UserId = Console.ReadLine();
Console.Write("请输入密码:");
string UserPwd = null;
#region 把密码显示星号输入
while (true)
{
//存储用户输入的按键,并且在输入的位置不显示字符
ConsoleKeyInfo ck = Console.ReadKey(true);
//判断用户是否按下的Enter键
if (ck.Key != ConsoleKey.Enter)
{
if (ck.Key != ConsoleKey.Backspace)
{
//将用户输入的字符存入字符串中
UserPwd += ck.KeyChar.ToString();
//将用户输入的字符替换为*
Console.Write("*");
}
else
{
//删除错误的字符
Console.Write("\b \b");
}
}
else
{
Console.WriteLine();
break;
}
}
Console.WriteLine("你刚才输入的密码是{0}", UserPwd);
#endregion
if (UserId.Equals("sa") && UserPwd.Equals("123456"))
{
SqlConnection sqlconnection = new SqlConnection("SERVER=.;Initial Catalog=MySchool;User ID=sa;Password=123456");//连接数据库
Console.Write("登录成功");
a = false;
}else
{
Console.Write("账号或密码有误,请重新输入");
a = true;
}
Console.ReadLine();
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
bool a = true;
while(a)
{
Console.Write("请输入账号:");
string UserId = Console.ReadLine();
Console.Write("请输入密码:");
string UserPwd = null;
#region 把密码显示星号输入
while (true)
{
//存储用户输入的按键,并且在输入的位置不显示字符
ConsoleKeyInfo ck = Console.ReadKey(true);
//判断用户是否按下的Enter键
if (ck.Key != ConsoleKey.Enter)
{
if (ck.Key != ConsoleKey.Backspace)
{
//将用户输入的字符存入字符串中
UserPwd += ck.KeyChar.ToString();
//将用户输入的字符替换为*
Console.Write("*");
}
else
{
//删除错误的字符
Console.Write("\b \b");
}
}
else
{
Console.WriteLine();
break;
}
}
Console.WriteLine("你刚才输入的密码是{0}", UserPwd);
#endregion
if (UserId.Equals("sa") && UserPwd.Equals("123456"))
{
SqlConnection sqlconnection = new SqlConnection("SERVER=.;Initial Catalog=MySchool;User ID=sa;Password=123456");//连接数据库
Console.Write("登录成功");
a = false;
}else
{
Console.Write("账号或密码有误,请重新输入");
a = true;
}
Console.ReadLine();
}
}
}
}