예제 #1
0
        public async Task <ValidationResult> CreateUser(AccountUserPostDto dto)
        {
            var password         = !string.IsNullOrWhiteSpace(dto.Password) ? MD5Hash.Generate(dto.Password) : null;
            var user             = CreateUserMapper(dto, password);
            var validationResult = await _userValidation.CreateValidation.ValidateAsync(user);

            if (!validationResult.IsValid)
            {
                return(validationResult);
            }

            _uow.UserRepository.Add(user);
            await _uow.CommitAsync();

            return(validationResult);
        }
예제 #2
0
        public AccountUserGetDto Login(AccountLoginDto dto)
        {
            var accountUserGetDto = new AccountUserGetDto();
            var password          = MD5Hash.Generate(dto.Password);
            var user = _uow.UserRepository.Get(dto.Username, password);

            if (user == null)
            {
                return(null);
            }

            var token = TokenService.GenerateToken(user);

            accountUserGetDto.Id       = user.Id;
            accountUserGetDto.Username = user.Username;
            accountUserGetDto.Role     = user.Role;
            accountUserGetDto.Token    = token;

            return(accountUserGetDto);
        }
        /// <summary>
        /// After receiving the IPN from SSLCommerz, it should be checked againsts
        /// its key values generated MD5 hash and verify_sign
        /// </summary>
        /// <param name="formValue"></param>
        /// <returns></returns>
        public bool VerifyIPNHash(IFormCollection formValue)
        {
            var verifyKey     = "verify_key";
            var verifySignKey = "verify_sign";

            if (string.IsNullOrWhiteSpace(formValue[verifyKey]) || string.IsNullOrWhiteSpace(formValue[verifySignKey]))
            {
                return(false);
            }

            var keyList   = formValue[verifyKey].ToString().Split(',').ToList <string>();
            var keyValues = new List <KeyValuePair <string, string> >();

            keyList.ForEach(key => keyValues.Add(new KeyValuePair <string, string>(key, formValue[key])));

            keyValues.Add(new KeyValuePair <string, string>(
                              "store_passwd",
                              MD5Hash.Generate(_config.StoreSecretKey)
                              ));

            keyValues.Sort(
                delegate(KeyValuePair <string, string> pair1, KeyValuePair <string, string> pair2)
            {
                return(pair1.Key.CompareTo(pair2.Key));
            }
                );

            var queryString = "";

            keyValues.ForEach(keyValue => queryString += $"{keyValue.Key}={keyValue.Value}&");
            queryString = queryString.TrimEnd('&');

            var generatedHash = MD5Hash.Generate(queryString);
            var verifySign    = formValue[verifySignKey].ToString();
            var isMatched     = MD5Hash.Verify(generatedHash, verifySign, true);

            return(isMatched);
        }