登录验证的三种方式(控制台)
2014-04-04 00:48
253 查看
第一种方式:
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
string str = CheckLogin(uid, pwd);
Console.WriteLine(str);
}
public static string CheckLogin(string uid, string pwd)
{
if (uid == "admin" && pwd == "888888")
{
return "登录成功";
}
else if (uid == "admin")
{
return "密码错误!";
}
else
{
return "用户名错误!";
}
}
第二种方式:
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pwd = Console.ReadLine();
string msg;
if (CL(uid, pwd, out msg))
{
Console.WriteLine("登录成功");
}
else
{
Console.WriteLine("登录失败,错误原因为:{0}", msg);
}
}
public static bool CL(string uid,string pwd,out string msg)
{
if (uid == "admin" && pwd == "888888")
{
msg = null;
return true;
}
else if (uid == "admin")
{
msg = "密码错误";
}
else
{
msg = "用户名错误";
}
return false;
}
第三种方式:
//与类平行
enum CK
{
Secuss,
Nouid,
Nopwd
}
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pwd = Console.ReadLine();
switch (Check(uid, pwd))
{
case CK.Secuss:
Console.WriteLine("登录成功");
break;
case CK.Nouid:
Console.WriteLine("用户名不存在");
break;
case CK.Nopwd:
Console.WriteLine("密码错误");
break;
}
}
public static CK Check(string uid, string pwd)
{
if (uid == "admin" && pwd == "888888")
{
return CK.Secuss;
}
else if (uid == "admin")
{
return CK.Nopwd;
}
else
{
return CK.Nouid;
}
}
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
string str = CheckLogin(uid, pwd);
Console.WriteLine(str);
}
public static string CheckLogin(string uid, string pwd)
{
if (uid == "admin" && pwd == "888888")
{
return "登录成功";
}
else if (uid == "admin")
{
return "密码错误!";
}
else
{
return "用户名错误!";
}
}
第二种方式:
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pwd = Console.ReadLine();
string msg;
if (CL(uid, pwd, out msg))
{
Console.WriteLine("登录成功");
}
else
{
Console.WriteLine("登录失败,错误原因为:{0}", msg);
}
}
public static bool CL(string uid,string pwd,out string msg)
{
if (uid == "admin" && pwd == "888888")
{
msg = null;
return true;
}
else if (uid == "admin")
{
msg = "密码错误";
}
else
{
msg = "用户名错误";
}
return false;
}
第三种方式:
//与类平行
enum CK
{
Secuss,
Nouid,
Nopwd
}
while (true)
{
Console.WriteLine("请输入用户名:");
string uid = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pwd = Console.ReadLine();
switch (Check(uid, pwd))
{
case CK.Secuss:
Console.WriteLine("登录成功");
break;
case CK.Nouid:
Console.WriteLine("用户名不存在");
break;
case CK.Nopwd:
Console.WriteLine("密码错误");
break;
}
}
public static CK Check(string uid, string pwd)
{
if (uid == "admin" && pwd == "888888")
{
return CK.Secuss;
}
else if (uid == "admin")
{
return CK.Nopwd;
}
else
{
return CK.Nouid;
}
}
相关文章推荐
- 【转】【Oracle】oracle登录验证的三种方式(详解)
- 单点登录的三种实现方式
- Sql Server 2005 怎么就不能用Windows身份验证方式登录呢?
- SQLSERVER误删Windows登录用户验证方式使用Windows身份验证的解决方法
- SSO单点登录三种情况的实现方式详解
- Oracle中的两种验证方式:操作系统验证和密码文件验证,通过操作系统验证的方式解决客户端登录不了数据的问题
- 另一种登录验证方式
- 单点登录(十四)-----实战-----cas5.0.x登录mongodb验证方式常规的四种加密的思考和分析
- MVC下的表单登录验证方式
- iOS实现简书的登录验证方式(极验验证)
- SSO单点登录三种情况的实现方式详解
- Linux学习之CentOS(二)----centos连接网络的三种方式及 远程登录管理工具SecureCRT的使用
- struts2: lesson four struts2的异常处理,validate验证,xml,annotation三种方式的验证,I18n国际化
- Centos远程登录三种方式telnet,ssh,vnc
- 单点登录的三种实现方式
- ms-sql登录验证方式错误解决办法
- CAS框架单点登录,自定义验证登录方式(添加系统标识)
- 配置SQL Server 2005 Express的身份验证方式,以及如何启用sa登录名
- 两系统用asp.net forms 身份验证方式实现跨域登录信息共享
- 单点登录的三种实现方式