示例#1
0
        // This can be tested by:
        // 1. Open the IAuthenticationService.cs file in this window. Follow the instructions listed there.
        public AuthenticationResponse NewUserRegistration(NewUserRegistrationRequest request)
        {
            var credential = DAL.Repositories.CredentialRepository.GetBy(1);

            try
            {
                if (string.IsNullOrEmpty(request.EmailAddress) || (request.EmailAddress.Length > MaxEmailAddressLength || request.EmailAddress.Length < MinEmailAddressLength))
                {
                    return(new AuthenticationResponse
                    {
                        Status = AuthenticationResponse.StatusMessage.Fail,
                        Message = "You must supply a valid email address.",
                        MessageDetails = string.Format("An email address must be at least {0} characters long and no more than {1} characters long.", MinEmailAddressLength, MaxEmailAddressLength)
                    });
                }
                if (string.IsNullOrEmpty(request.Password) || (request.Password.Length < MinPasswordLength || request.Password.Length > MaxPasswordLength) || request.Password.Contains(request.EmailAddress))
                {
                    return(new AuthenticationResponse
                    {
                        Status = AuthenticationResponse.StatusMessage.Fail,
                        Message = "You must supply a valid password.",
                        MessageDetails = string.Format("Passwords must be at least {0} characters long and no more than {1} characters long.", MinPasswordLength, MaxPasswordLength)
                    });
                }

                var salt           = GenerateSalt(EncryptedSaltLength);
                var saltedPassword = CalculateSha1(request.Password, salt, EncryptionIterations, EncryptedHashLength);

                return(new AuthenticationResponse
                {
                    Status = AuthenticationResponse.StatusMessage.Ok,
                    Message = string.Format("New You entered: {0}", request.EmailAddress)
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
        // This can be tested by:
        // 1. Open the IAuthenticationService.cs file in this window. Follow the instructions listed there.
        public AuthenticationResponse NewUserRegistration(NewUserRegistrationRequest request)
        {
            var credential = DAL.Repositories.CredentialRepository.GetBy(1);
            try
            {
                if (string.IsNullOrEmpty(request.EmailAddress) || (request.EmailAddress.Length > MaxEmailAddressLength || request.EmailAddress.Length < MinEmailAddressLength))
                {
                    return new AuthenticationResponse
                    {
                        Status = AuthenticationResponse.StatusMessage.Fail,
                        Message = "You must supply a valid email address.",
                        MessageDetails = string.Format("An email address must be at least {0} characters long and no more than {1} characters long.", MinEmailAddressLength, MaxEmailAddressLength)
                    };
                }
                if (string.IsNullOrEmpty(request.Password) || (request.Password.Length < MinPasswordLength || request.Password.Length > MaxPasswordLength) || request.Password.Contains(request.EmailAddress))
                {
                    return new AuthenticationResponse
                    {
                        Status = AuthenticationResponse.StatusMessage.Fail,
                        Message = "You must supply a valid password.",
                        MessageDetails = string.Format("Passwords must be at least {0} characters long and no more than {1} characters long.", MinPasswordLength, MaxPasswordLength)
                    };
                }

                var salt = GenerateSalt(EncryptedSaltLength);
                var saltedPassword = CalculateSha1(request.Password, salt, EncryptionIterations, EncryptedHashLength);

                return new AuthenticationResponse
                {
                    Status = AuthenticationResponse.StatusMessage.Ok,
                    Message = string.Format("New You entered: {0}", request.EmailAddress)
                };
            }
            catch (Exception)
            {
                throw;
            }
        }