Ejemplo n.º 1
0
        public string ResetPassword(int userId)
        {
            string[] randoms = new string[10];
            randoms[0] = "AV";
            randoms[1] = "xf";
            randoms[2] = "d12";
            randoms[3] = "fbt";
            randoms[4] = "f4sa";
            randoms[5] = "a!z";
            randoms[6] = "s@j7";
            randoms[7] = "3d";
            randoms[8] = "!f6";
            randoms[9] = "fF";
            Random r        = new Random();
            string randsror = randoms[r.Next(0, randoms.Length - 1)];

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("dbo.ResetPassword", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@userId", userId);
                cmd.Parameters.AddWithValue("@password", HelperRepository.EncryptPassword(randsror));
                cmd.ExecuteNonQuery();
            }
            return(randsror);
        }
Ejemplo n.º 2
0
        public void ChangePassword(string password, string username)
        {
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("dbo.ChangePassword", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@userName", username);
                cmd.Parameters.AddWithValue("@password", HelperRepository.EncryptPassword(password));
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 3
0
        public string AddUser(NewUser model)
        {
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("dbo.AddUser", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", model.Surname + " " + model.Name);
                cmd.Parameters.AddWithValue("@login", model.Login);
                cmd.Parameters.AddWithValue("@password", HelperRepository.EncryptPassword(model.Password));
                cmd.Parameters.AddWithValue("@roleId", model.RoleId);
                return(Convert.ToString(cmd.ExecuteScalar()));
            }
        }
Ejemplo n.º 4
0
        public Response <UserModel> ValidateUser(LoginModel model)
        {
            Response <UserModel> response = new Response <UserModel>();

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("dbo.ValidateUser", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@userName", model.Login);
                    cmd.Parameters.AddWithValue("@password", HelperRepository.EncryptPassword(model.Password));
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (!reader.HasRows)
                    {
                        throw new Exception("Неверный логин или пароль!");
                    }

                    response.Data = new UserModel();
                    while (reader.Read())
                    {
                        response.Data.Id       = reader["Id"] != DBNull.Value ? Convert.ToInt32(reader["Id"]) : 0;
                        response.Data.Name     = reader["Name"] != DBNull.Value ? Convert.ToString(reader["Name"]) : string.Empty;
                        response.Data.UserName = reader["UserName"] != DBNull.Value ? Convert.ToString(reader["UserName"]) : string.Empty;
                        response.Data.RoleGUID = reader["RoleGUID"] != DBNull.Value ? Convert.ToString(reader["RoleGUID"]) : string.Empty;
                    }
                    response.Code    = 1;
                    response.Message = "success";
                }
                catch (Exception ex)
                {
                    response.Code    = -1;
                    response.Message = ex.Message;
                }
            }
            return(response);
        }