小弟正在做一个网页作业。网页要求密码登录后才可以转到其他页面。
1.登录界面如下:
2. 如果没有用户帐号,可以创建一个新的,新的帐号密码将写到数据库里面。数据库的表如下:
CREATE TABLE userlogin
(
userid varchar(30),
password varchar(30)
)3.我设计了一个STORED PROCEDURE写入数据。如下
--这部分没问题了,把这个存储过程链接到VISUAL STUDIO里面的WEB PAGE也能成功插入数据到数据库里面
CREATE PROCEDURE insert_pw
@userid varchar(30), @password varchar(30)
AS
BEGIN
INSERT INTO userlogin VALUES (@userid, HASHBYTES (‘SHA1’, @password))
END
GO
4. 在VISUAL 里面,我用了两个TEXTBOX分别用来写入SP的两个参数@userid, @password。 一个button用来提交。写入成功
5. 现在问题出在我不知道如何把刚写入的密码登录。登录后可以显示的界面大概是这样的:希望大神们指教一下我如何使用已经保存在数据库里面的用户名和密码登录到其他界面

解决方案 »

  1.   

    讲了一大堆大概明白你说的是什么不就是一跳查询语句啊
     string sql = "select AccountID,Password,Remaining from dbo.Account where AccountID=@AccountID and Password=@Password";
               SqlParameter sp1 = new SqlParameter("@AccountID", AccountID);
               SqlParameter sp2 = new SqlParameter("@Password", Password);
               return SqlHepler.ExecuteScalar(sql, sp1, sp2);
    在写个方法调用一下
    Commom.Bean.Account bean = new Commom.Bean.Account();
            bean.Accountid = TextBox1.Text;
            bean.Password = TextBox2.Text;
            bool Login = BuessinessLogic.Account.Login(bean);
            if (Login)
            {
                Session["Bean"] = bean;
                Response.Redirect("Index.aspx");
            }
            else
            {
                Commom.Method.MessageBox.Show("登录失败", this);
            }
      

  2.   

    用mvc,新建、修改、删除、登录    你都不用管了
      

  3.   


    还是不太明白,我这边没有用存储过程。只要和数据库里面有存在的userid和password对应就行了
      

  4.   

    刚开始学,写个简单点,搞什么mvc啊,走都不会,还要飞
      

  5.   


    //登录验证函数
     public static bool login_ms(String sql)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
            //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ToString ());
            con.Open();
            SqlCommand com = new SqlCommand(sql, con);
         
            try
            {
                int isEx = Convert.ToInt32(com.ExecuteScalar());
                if (isEx > 0)
                {
                    con.Close();
                    return true;
                }
                else
                {
                    con.Close();
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }//登录函数
     private void UserLogin_MS()
        {
            if (txtsno.Text != "" && txtpw.Text != "")
            {
                if (txtsno.Text.Length >= 6)
                {
                    try
                    {
                        string str = "select count(*) from Student where Accounts='" + txtsno.Text.Trim().Replace("'", "\"") + "' and  isnull(Password,'" + txtpw.Text + "')='" + txtsno.Text.Trim().Substring(txtsno.Text.Length - 6, 6) + "' or Password='" + txtpw.Text.Trim().Replace("'", "\"") + "'and Accounts='" + txtsno.Text.Trim().Replace("'", "\"") + "'";                    if (Method.login_ms(str))//判断是否是合法用户
                        {
                          Response.Redirect("MainIndex.aspx");//跳转页面                    }
                        else
                        {
                            informlb.Text = "输入错误,请检查";
                        }
                    }
                    catch
                    {
                        informlb.Text = "数据异常!";
                    }            }
                else
                {
                    informlb.Text = "ID号输入错误";
                }
            }
            else
            {
                informlb.Text = "ID号和密码不能为空!";
            }
        }