Пример #1
0
 public bool ValidateUser()
 {
     try
     {
         using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
         {
             using (SqlCommand SqlCommand = new SqlCommand("spValidateUser", con))
             {
                 ds = new DataSet("Users");
                 SqlCommand.CommandType = CommandType.StoredProcedure;
                 SqlCommand.Parameters.Clear();
                 SqlCommand.Parameters.AddWithValue("@UserName", UserName);
                 if (con.State == ConnectionState.Closed)
                 {
                     con.Open();
                 }
                 SQAdapter.SelectCommand = SqlCommand;
                 SQAdapter.Fill(ds, "Users");
                 if (ds.Tables["Users"].Rows.Count > 0)
                 {
                     String CipherString = (ds.Tables["Users"].Rows[0]["Password"]).ToString();
                     if (SkypensionCryptoEngine.Decrypt(CipherString, true).Equals(Password))
                     {
                         return(true);
                     }
                 }
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
    public bool ValidateUser()
    {
        try
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
            {
                using (SqlCommand SqlCommand = new SqlCommand("spValidateUser", con))
                {
                    DataSet ds = new DataSet("Users");
                    SqlCommand.CommandType = CommandType.StoredProcedure;
                    SqlCommand.Parameters.Clear();
                    SqlCommand.Parameters.AddWithValue("@UserName", UserName);
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    SQAdapter.SelectCommand = SqlCommand;
                    SQAdapter.Fill(ds, "Users");
                    if (ds.Tables["Users"].Rows.Count > 0)
                    {
                        String CipherString = (ds.Tables["Users"].Rows[0]["Password"]).ToString();
                        if (SkypensionCryptoEngine.Decrypt(CipherString, true).Equals(Password))
                        {
                            UserNameCookie.Value = this.UserName;

                            HttpContext.Current.Response.Cookies.Add(UserNameCookie);


                            return(true);
                        }
                    }
                    return(false);
                }
            }
        }
        catch (Exception ex)
        {
            Security secs = new Security();
            secs.ErrorDesscription = ex.Message;
            secs.Terminus          = Environment.MachineName;
            secs.ErrorModule       = "Validating User-Login";
            secs.SaveError();
            throw (ex);
            //return false;
        }
    }