本文介绍了Logen和密码请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道签到什么问题



i don''t know What the Problem to sign in

    public bool SearchUser(string Name, Guid Password)
    {
    bool flagResult = false;
        using (SqlConnection con = new SqlConnection(constring))
        {

            SqlCommand com = new SqlCommand("StoredProcedure4", con);
            com.CommandType = System.Data.CommandType.StoredProcedure;

            SqlParameter param = new SqlParameter();
            param.ParameterName = "@UName";
            param.Value = Name;
            param.SqlDbType = System.Data.SqlDbType.NVarChar;
            param.Direction = System.Data.ParameterDirection.Input;
            com.Parameters.Add(param);

             param = new SqlParameter();
             param.ParameterName = "@UPassword";
             param.Value = Password;
            param.SqlDbType = System.Data.SqlDbType.NVarChar;
            param.Direction = System.Data.ParameterDirection.Input;
            com.Parameters.Add(param);


            try
            {
               con.Open();
                if (com.ExecuteNonQuery() == 1)
                    flagResult = true;
            }
            catch
            {

            }
            return flagResult;

        }

        }
        }
}




存储过程中的






in Stored Procedurs

ALTER PROCEDURE dbo.StoredProcedure4
	
	(
	@UName nvarchar(50),
	@UPassword nvarchar (50)
	
	)
	
AS


	SELECT * FROM Users WHERE UserName = @UName AND
	
	cast (Password as nvarchar (50)) = @UPassword

	


	RETURN





我的Logen





my Logen

public partial class Logen : Form
 {
     DAL dal = new DAL();

     public Logen()
     {
         InitializeComponent();
     }

     private void login_Click(object sender, EventArgs e)
     {

              if (dal.SearchUser(log.Text.Trim(),
     GetHashString(pass.Text.Trim())))


             this.DialogResult = DialogResult.OK;
         else
             this.DialogResult = DialogResult.No;
     }

     Guid GetHashString(string s)
     {
         byte[] bytevalue = Encoding.Unicode.GetBytes(s);
         MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();

         byte[] byteHash = csp.ComputeHash(bytevalue);

         string rez = string.Empty;
         foreach (byte b in byteHash)

             rez += string.Format("{0:x2}",b);

         return new Guid (rez);

     }
 }
     }

推荐答案


using (SqlConnection con = new SqlConnection(constring))
{
    using (SqlCommand cmd = new SqlCommand("StoredProcedure4", con))
    {
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@UName", name);
        cmd.Parameters.AddWithValue("@UPassword", Password.ToString());
        try
        {
            con.Open();
            if (cmd.ExecuteNonQuery() == 1)
                flagResult = true;
        }
        catch
        {

        }
        return flagResult;

    }
}


这篇关于Logen和密码请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:28