Exemplo n.º 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            String userId   = txtUserName.Text;
            String pwd      = txtPwd.Text;
            String userDesc = txtUserDesc.Text;

            MD5 md5 = new MD5CryptoServiceProvider();

            byte[] result = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(pwd));
            String pwdMd5 = Convert.ToBase64String(result);

            try
            {
                DbaseCS.ExecuteNonQuery("insert t_User values(@UserID,@UserPwd,@UserDesc)",
                                        new SqlParameter[] {
                    new SqlParameter("@UserID", userId),
                    new SqlParameter("@UserPwd", pwdMd5),
                    new SqlParameter("@UserDesc", userDesc)
                },
                                        CmdType.CmdTxt);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        bool IsValiadUses(String userName, String pwd)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            byte[] result = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(pwd));
            String pwdMd5 = Convert.ToBase64String(result);

            object userId = DbaseCS.ExecuteScalar("select UserID from t_User where UserID=@UserID and UserPwd=@UserPwd",
                                                  new SqlParameter[] { new SqlParameter("@UserID", userName),
                                                                       new SqlParameter("@UserPwd", pwdMd5) }, CmdType.CmdTxt);

            if (userId != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }