Exemplo n.º 1
0
        public AgentResponse AddAgent(string login, string password, string name, bool isTest)
        {
            string        token = HelperRepository.EncrypteText(login + DateTime.Now + password + name).Substring(0, 60);
            bool          isAdd = false;
            AgentResponse agent = new AgentResponse();

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

                SqlCommand cmd = new SqlCommand("dbo.AddAgent", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@login", login);
                cmd.Parameters.AddWithValue("@password", HelperRepository.EncrypteText(password));
                cmd.Parameters.AddWithValue("@isTest", isTest);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.Parameters.AddWithValue("@token", token);
                isAdd = Convert.ToBoolean(cmd.ExecuteScalar());
            }
            if (isAdd)
            {
                agent.Login    = login;
                agent.Token    = token;
                agent.Password = password;
                return(agent);
            }
            else
            {
                throw new Exception("Не удалось добавить агента");
            }
        }
Exemplo n.º 2
0
 public bool IsValid(string login, string password, string token)
 {
     if (token == adminToken)
     {
         return(true);
     }
     return(IsValidApi(login, HelperRepository.EncrypteText(password), token));
 }
Exemplo n.º 3
0
        public bool ChangePassword(string login, string newPassword)
        {
            using (SqlConnection conn = new SqlConnection(_connectionStringAccount))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("dbo.ChangePassword", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@login", login);
                cmd.Parameters.AddWithValue("@newPassword", HelperRepository.EncrypteText(newPassword));
                cmd.ExecuteNonQuery();
                return(true);
            }
        }
Exemplo n.º 4
0
        public AccountLoginModel GetAccount(string login, string password)
        {
            AccountLoginModel account = new AccountLoginModel();

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

                SqlCommand cmd = new SqlCommand("dbo.GetAccount", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@login", login);
                cmd.Parameters.AddWithValue("@password", HelperRepository.EncrypteText(password));
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    account.Login = reader["Login"] != DBNull.Value ? Convert.ToString(reader["Login"]) : string.Empty;
                    account.Token = HelperRepository.EncrypteText(reader["Token"] != DBNull.Value ? Convert.ToString(reader["Token"]) : string.Empty);
                }
            }
            return(account);
        }