用C#提示用户输入用户名,然后再提示输入密码,如果用户名是“admin”并且密码是“888888”, 则提示正确
10个回答
展开全部
Console.WriteLine("请输入用户名:");
string name = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pw = Console.ReadLine();
if (name == "admin" && pw == "88888")
{
Console.WriteLine("密码正确!");
}
else if (name != "admin")
{
Console.WriteLine("用户名不存在");
}
else
{
Console.WriteLine("密码错误");
}
string name = Console.ReadLine();
Console.WriteLine("请输入密码:");
string pw = Console.ReadLine();
if (name == "admin" && pw == "88888")
{
Console.WriteLine("密码正确!");
}
else if (name != "admin")
{
Console.WriteLine("用户名不存在");
}
else
{
Console.WriteLine("密码错误");
}
展开全部
int a;
string s1,s2;
lop:Console.WriteLine("请输入您的用户名:\n");
s1 = Console.ReadLine();
while(s1!="admin")
{
Console.WriteLine("此用户名不存在,请查证后重新输入!\n");
goto lop;
}
lop1:Console.WriteLine("请输入密码:\n");
s2=Console .ReadLine ();
a = Convert.ToInt32(s2);
while (a!= 888888)
{
Console.WriteLine("密码错误,请重新输入!\n");
goto lop1;
}
Console.WriteLine("登陆成功!\n");
string s1,s2;
lop:Console.WriteLine("请输入您的用户名:\n");
s1 = Console.ReadLine();
while(s1!="admin")
{
Console.WriteLine("此用户名不存在,请查证后重新输入!\n");
goto lop;
}
lop1:Console.WriteLine("请输入密码:\n");
s2=Console .ReadLine ();
a = Convert.ToInt32(s2);
while (a!= 888888)
{
Console.WriteLine("密码错误,请重新输入!\n");
goto lop1;
}
Console.WriteLine("登陆成功!\n");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
估计你是C#面向对象吧,
Console.WriteLine("请输入用户名");
string name=Console.ReadLine();
string name= Console.ReadLine();
if (name.Equals("Admin"))
{
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
if (pwd.Equals("8888"))
{
Console.WriteLine("登录成功");
}
}
Console.WriteLine("请输入用户名");
string name=Console.ReadLine();
string name= Console.ReadLine();
if (name.Equals("Admin"))
{
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
if (pwd.Equals("8888"))
{
Console.WriteLine("登录成功");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
C#的代码没有带在身上,这个一段ASP.NET的,主要代码基本同理。这是一个带ACCESS数据库的,数据库名:construction.mdb,数据库密码:lidehui。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection oledbconn = new OleDbConnection();
public void conn()
{
oledbconn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source ="+Server.MapPath("construction.mdb")+";Jet OLEDB:Database Password=lidehui;";
}
public void login()
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
conn();
try
{
oledbconn.Open();
}
catch (OleDbException ex)
{
Response.Write(ex.ToString());
//Response.Write("<script language='javascript'>alert('连接错误!'+ex)</script>");
return;
}
if (TextBox1.Text != "")
{
if (TextBox2.Text != "")
{
string login_str;
OleDbCommand login_cmd = new OleDbCommand();
OleDbDataReader login_dr;
login_str = "select * from user_info where user_name='" + TextBox1.Text.ToString().Trim() + "' and user_pwd='" + TextBox2.Text.ToString().Trim() + "'and user_power='" + DropDownList1.SelectedItem.Text.ToString().Trim() + "'";
login_cmd.CommandType = CommandType.Text;
login_cmd.CommandText = login_str;
login_cmd.Connection = oledbconn;
login_dr = login_cmd.ExecuteReader();
if (login_dr.Read())
{
Response.Redirect("Default2.aspx");
}
else
{
Response.Write("<script language='javascript'>alert('登陆无效!')</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('密码为空!')</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('用户名为空!')</script>");
}
oledbconn.Close();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection oledbconn = new OleDbConnection();
public void conn()
{
oledbconn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source ="+Server.MapPath("construction.mdb")+";Jet OLEDB:Database Password=lidehui;";
}
public void login()
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
conn();
try
{
oledbconn.Open();
}
catch (OleDbException ex)
{
Response.Write(ex.ToString());
//Response.Write("<script language='javascript'>alert('连接错误!'+ex)</script>");
return;
}
if (TextBox1.Text != "")
{
if (TextBox2.Text != "")
{
string login_str;
OleDbCommand login_cmd = new OleDbCommand();
OleDbDataReader login_dr;
login_str = "select * from user_info where user_name='" + TextBox1.Text.ToString().Trim() + "' and user_pwd='" + TextBox2.Text.ToString().Trim() + "'and user_power='" + DropDownList1.SelectedItem.Text.ToString().Trim() + "'";
login_cmd.CommandType = CommandType.Text;
login_cmd.CommandText = login_str;
login_cmd.Connection = oledbconn;
login_dr = login_cmd.ExecuteReader();
if (login_dr.Read())
{
Response.Redirect("Default2.aspx");
}
else
{
Response.Write("<script language='javascript'>alert('登陆无效!')</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('密码为空!')</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('用户名为空!')</script>");
}
oledbconn.Close();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(!string.IsNullOrEmpty(UserName.Text))
{
if(UserName.Text=="admin"&&PassWord.Text=="888888")
LabelMessage.Text = "正确";
else LabelMessage.Text = "错误";
}
else LabelMessage.Text = "请先输入密码!";
{
if(UserName.Text=="admin"&&PassWord.Text=="888888")
LabelMessage.Text = "正确";
else LabelMessage.Text = "错误";
}
else LabelMessage.Text = "请先输入密码!";
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询