예제 #1
0
        public PasswordLogin PasswordLogin([FromBody] PasswordLogin login)
        {
            try
            {
                string connectionString = configuration.GetConnectionString("DefaultConnection");
                connectionFactory = ConnectionHelper.GetConnection(connectionString);

                var context = new DbContext(connectionFactory);

                var userRep = new CustomerRepository(context);
                var result  = userRep.PasswordLogin(login);
                if (result != null)
                {
                    login.Message = "success";
                    return(login);
                }
                else
                {
                    login.Message = "Customer does not exist.";
                    return(login);
                }
            }
            catch (Exception ex)
            {
                login.Message = ex.Message;
                return(login);
            }
        }
예제 #2
0
 public AnnPages.AccountHomePage GoToAccountHomePage()
 {
     NavigateToUrl(urlAliexpress);
     Thread.Sleep(2000);
     driver.Manage().Window.FullScreen();
     Thread.Sleep(15000);
     try
     {
         Click(CloseAdvertising);
     }
     catch (NoSuchElementException)
     { }
     Thread.Sleep(2000);
     Click(ButtonLogin);
     Thread.Sleep(8000);
     driver.SwitchTo().Frame(driver.FindElement(By.Id(aliExpressLoginFormId)));
     EmailLogin.Clear();
     SendText(EmailLogin, "*****@*****.**");
     Thread.Sleep(1000);
     PasswordLogin.Clear();
     SendText(PasswordLogin, "qLEvZxcMVU9xqdQC");
     Thread.Sleep(1000);
     Click(ButtonSubmit);
     Thread.Sleep(7000);
     try
     {
         Click(CloseAdvertising);
     }
     catch (NoSuchElementException)
     { }
     Thread.Sleep(5000);
     Click(MyAliExpressBtn);
     return(new AnnPages.AccountHomePage(driver));
 }
        public void SuccessfullAuthentication()
        {
            var userManager = new UserManager();
            var services    = new ServiceCollection()
                              .AddLogging()
                              .AddSingleton <IUserManager <int> >(userManager)
                              .AddLoginAuthentication(b => b.AddPasswordAuthentication <UserManager, int>())
                              .BuildServiceProvider(true);

            using (var scope = services.CreateScope())
            {
                var auth = scope.ServiceProvider.GetRequiredService <ILoginAuthentication>();
                var pwd  = PasswordLogin.GeneratePaswordHash("xasd");
                userManager.Users.Add(new User
                {
                    Id         = 1,
                    Email      = "*****@*****.**",
                    FamilyName = "a",
                    GivenName  = "b",
                    Password   = pwd.Hash,
                    Salt       = pwd.Salt
                });
                CultureInfo.CurrentCulture   = CultureInfo.InvariantCulture;
                CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
                var p = auth.AuthenticateAsync("password", "[email protected]:xasd").Result;
                Assert.True(p.Identity.IsAuthenticated);
                Assert.Equal("1", p.FindFirst(ClaimTypes.Sid)?.Value);
                Assert.Equal("a", p.FindFirst(ClaimTypes.Surname)?.Value);
                Assert.Equal("b", p.FindFirst(ClaimTypes.GivenName)?.Value);
                Assert.Equal("b a", p.FindFirst(ClaimTypes.Name)?.Value);
                Assert.Equal("*****@*****.**", p.FindFirst(ClaimTypes.Email)?.Value);
            }
        }
        private async Task _loginMethodAsync()
        {
            string urlLogin = ApiRouteHelper.GetAccountControllerLoginRoute();

            var response = await WebRequests.PostJsonAsync
                           (
                urlLogin,
                new LoginApiRequest
            {
                Email    = EmailLogin,
                Password = PasswordLogin.Unsecure()
            });

            if (response.IsSuccessStatusCode)
            {
                AuthenticateApiResponse result = JsonConvert.DeserializeObject <AuthenticateApiResponse>(response.Content.ReadAsStringAsync().Result);
                // ToDo: сделать с NavigationService
                //var appVM = DI.ServiceProvider.GetService<ApplicationWindowViewModel>();
                //await appVM.EntryToAppAsync(result.Email, result.Jwt, result.RefreshToken);
            }
            else
            {
                // Добавить в чём ошибка
            }
        }
예제 #5
0
 public bool UpdateEmailConfirmationStatus(string userName, string otp)
 {
     try
     {
         PasswordLogin passwordLogin = _authenticationRepository.GetLoginPassword(userName);
         var           otpDetails    = _authenticationRepository.GetOtp(passwordLogin.UserId);
         if (otpDetails.otp == otp)
         {
             _authenticationRepository.UpdateEmailConfirmationStatus(passwordLogin.UserId, true);
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         _logger.LogException(new ExceptionLog
         {
             ExceptionDate   = DateTime.Now,
             ExceptionMsg    = ex.Message,
             ExceptionSource = ex.Source,
             ExceptionType   = "UserService",
             FullException   = ex.StackTrace
         });
         return(false);
     }
 }
예제 #6
0
 public void LoginToAccount()
 {
     NavigateToUrl(urlAliexpress);
     Thread.Sleep(2000);
     driver.Manage().Window.FullScreen();
     Thread.Sleep(15000);
     if (CloseAdvertising.Displayed)
     {
         Click(CloseAdvertising);
     }
     Thread.Sleep(2000);
     Click(ButtonLogin);
     Thread.Sleep(8000);
     driver.SwitchTo().Frame(driver.FindElement(By.Id(aliExpressLoginFormId)));
     EmailLogin.Clear();
     SendText(EmailLogin, alijson.Email);
     // SendText(EmailLogin, "*****@*****.**");
     Thread.Sleep(1000);
     PasswordLogin.Clear();
     SendText(PasswordLogin, alijson.Password);
     // SendText(PasswordLogin, "qLEvZxcMVU9xqdQC");
     Thread.Sleep(1000);
     Click(ButtonSubmit);
     Thread.Sleep(7000);
 }
예제 #7
0
        public int PasswordChangeLog(PasswordLogin passwordLogin)
        {
            using IDbConnection db = _connectionFactory.GetConnection;

            string query = @"Insert into [PasswordLog](UserId, PasswordHash, PasswordSalt, ChangeDate) 
                values (@UserId, @PasswordHash, @PasswordSalt, @ChangeDate)";

            return(db.Execute(query, new { passwordLogin.UserId, passwordLogin.PasswordHash, passwordLogin.PasswordSalt, ChangeDate = DateTime.Now }));
        }
예제 #8
0
        public bool UpdatePasswordLogin(PasswordLogin passwordLogin)
        {
            string query = @"update [PasswordLogin] Set 
                                PasswordHash = @PasswordHash,
                                PasswordSalt = @PasswordSalt
                            Where UserId = @UserId";

            using IDbConnection db = _connectionFactory.GetConnection;
            db.Execute(query, passwordLogin);
            return(true);
        }
예제 #9
0
 public void Login()
 {
     //bool jwt_Ishave = Static.Instance.Getjwt();
     //if(jwt_Ishave)
     //JwtLogin.Get();
     //else
     if (UserProtocolTgl.isOn)
     {
         PasswordLogin.Get();
     }
     else
     {
         string content    = GlobalData.CONSENT_TO_THE_TERMS_OF_THE_USER,
                buttonName = GlobalData.submit,
                title      = GlobalData.prompt;
         MessageManager._Instantiate.WindowShowMessage(content, null, buttonName, title, true);
     }
 }
예제 #10
0
        public CustomerModel PasswordLogin(PasswordLogin model)
        {
            try
            {
                using (var command = _context.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = $"select * from tblCustomer where Password='******' and userName='******'";

                    var result = this.ToList(command).FirstOrDefault();


                    return(result);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #11
0
        public int Insert(User user, PasswordLogin passwordLogin)
        {
            var p = new DynamicParameters();

            p.Add("Id", 0, DbType.Int32, ParameterDirection.Output);
            p.Add("@UserName", user.UserName);
            p.Add("@FirstName", user.FirstName);
            p.Add("@LastName", user.LastName);
            p.Add("@Email", user.Email);
            p.Add("@Mobile", user.Mobile);
            p.Add("@Country", user.Country);
            p.Add("@ISDCode", user.ISDCode);
            p.Add("@TwoFactor", user.TwoFactor);
            p.Add("@Locked", user.Locked);
            p.Add("@IsActive", user.IsActive);
            p.Add("@EmailValidationStatus", user.EmailValidationStatus);
            p.Add("@MobileValidationStatus", user.MobileValidationStatus);
            p.Add("@OrgId", user.OrgId);
            p.Add("@AdminLevel", user.AdminLevel);

            string userInsertQuery = @"Insert into [User](UserName, FirstName, LastName, Email, Mobile, Country, ISDCode, TwoFactor, Locked, IsActive, EmailValidationStatus, MobileValidationStatus, OrgId, AdminLevel) 
                values (@UserName, @FirstName, @LastName, @Email, @Mobile, @Country, @ISDCode, @TwoFactor, @Locked, @IsActive, @EmailValidationStatus, @MobileValidationStatus, @OrgId, @AdminLevel);
                SELECT @Id = @@IDENTITY";

            string passwordLoginInsertQuery = @"Insert into [PasswordLogin](PasswordHash, PasswordSalt, UserId) 
                values (@PasswordHash, @PasswordSalt, @UserId)";

            using IDbConnection db = _connectionFactory.GetConnection;
            using var transaction  = db.BeginTransaction();
            db.Execute(userInsertQuery, p, transaction);

            int insertedUserId = p.Get <int>("@Id");

            passwordLogin.UserId = insertedUserId;
            db.Execute(passwordLoginInsertQuery, passwordLogin, transaction);
            transaction.Commit();

            return(insertedUserId);
        }
예제 #12
0
        public bool ChangePassword(ChangedPassword newPassword)
        {
            bool result = false;

            try
            {
                if (newPassword.NewPassword == newPassword.ConfirmPassword)
                {
                    PasswordLogin passwordLogin = _authenticationRepository.GetLoginPassword(newPassword.UserName);
                    if (Hasher.ValidateHash(newPassword.CurrentPassword, passwordLogin.PasswordSalt,
                                            passwordLogin.PasswordHash, out _))
                    {
                        PasswordLogin newPasswordLogin = Hasher.HashPassword(newPassword.NewPassword);
                        newPasswordLogin.UserId     = passwordLogin.UserId;
                        newPasswordLogin.ChangeDate = DateTime.Now;
                        passwordLogin = newPasswordLogin;
                        _authenticationRepository.UpdatePasswordLogin(newPasswordLogin);
                        result = true;
                    }

                    //TODO: this should be a async operation and can be made more cross-cutting design feature rather than calling inside the actual feature.
                    _logger.PasswordChangeLog(passwordLogin);
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(new ExceptionLog
                {
                    ExceptionDate   = DateTime.Now,
                    ExceptionMsg    = ex.Message,
                    ExceptionSource = ex.Source,
                    ExceptionType   = "UserService",
                    FullException   = ex.StackTrace
                });
                return(result);
            }

            return(result);
        }
예제 #13
0
        public bool ForgotPassword(ForgotPassword forgotPassword)
        {
            bool result = false;

            try
            {
                if (forgotPassword.NewPassword == forgotPassword.ConfirmPassword)
                {
                    PasswordLogin passwordLogin = _authenticationRepository.GetLoginPassword(forgotPassword.UserName);
                    var           otpDetails    = _authenticationRepository.GetOtp(passwordLogin.UserId);
                    if (otpDetails.otp == forgotPassword.otp)
                    {
                        var newPasswordLogin = Hasher.HashPassword(forgotPassword.NewPassword);
                        newPasswordLogin.UserId     = passwordLogin.UserId;
                        newPasswordLogin.ChangeDate = DateTime.Now;
                        passwordLogin = newPasswordLogin;
                        _authenticationRepository.UpdatePasswordLogin(newPasswordLogin);
                        result = true;
                    }

                    //TODO: this should be a async operation and can be made more cross-cutting design feature rather than calling inside the actual feature.
                    _logger.PasswordChangeLog(passwordLogin);
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(new ExceptionLog
                {
                    ExceptionDate   = DateTime.Now,
                    ExceptionMsg    = ex.Message,
                    ExceptionSource = ex.Source,
                    ExceptionType   = "UserService",
                    FullException   = ex.StackTrace
                });
                return(result);
            }

            return(result);
        }
예제 #14
0
        public RequestResult <bool> Insert(SessionContext sessionContext, User user, string password)
        {
            List <ValidationMessage> validationMessages = new List <ValidationMessage>();

            try
            {
                if (!Helpers.IsInOrganizationContext(sessionContext, user.OrgId))
                {
                    var error = new ValidationMessage {
                        Reason = "You can only register users in your organization", Severity = ValidationSeverity.Error
                    };
                    validationMessages.Add(error);
                    return(new RequestResult <bool>(false, validationMessages));
                }

                var passwordPolicy   = _securityParameterRepository.Get(sessionContext, user.OrgId);
                var validatePassword = Helpers.ValidatePassword(password, passwordPolicy);
                if (validatePassword.IsSuccessful)
                {
                    PasswordLogin passwordLogin = Hasher.HashPassword(password);
                    _userRepository.Insert(user, passwordLogin);
                    return(new RequestResult <bool>(true));
                }

                return(new RequestResult <bool>(false, validatePassword.ValidationMessages));
            }
            catch (Exception ex)
            {
                _logger.LogException(new ExceptionLog
                {
                    ExceptionDate   = DateTime.Now,
                    ExceptionMsg    = ex.Message,
                    ExceptionSource = ex.Source,
                    ExceptionType   = "UserService",
                    FullException   = ex.StackTrace
                });
                return(new RequestResult <bool>(false));
            }
        }
예제 #15
0
        public bool SendOtp(string userName)
        {
            try
            {
                PasswordLogin passwordLogin = _authenticationRepository.GetLoginPassword(userName);
                var           user          = _userRepository.Get(passwordLogin.UserId);
                string        otp           = GenericUtil.GenerateOTP().ToString();
                new KromeEmail().SendEmail(user.Email, otp, GenericUtil.OTPTransType.PasswordReset);
                new KromeSMS().SendSMS(user.Mobile, otp, GenericUtil.OTPTransType.PasswordReset);

                UserValidationOtp userValidationOtp = new UserValidationOtp
                {
                    UserId = passwordLogin.UserId,
                    OrgId  = user.OrgId,
                    otp    = otp,
                    OtpAuthenticatedTime = DateTime.Now,
                    OtpGeneratedTime     = DateTime.Now,
                    Status = (int)GenericUtil.OTPTransType.PasswordReset,
                    Type   = GenericUtil.OTPTransType.PasswordReset.ToString()
                };

                _authenticationRepository.SaveOtp(userValidationOtp);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogException(new ExceptionLog
                {
                    ExceptionDate   = DateTime.Now,
                    ExceptionMsg    = ex.Message,
                    ExceptionSource = ex.Source,
                    ExceptionType   = "UserService",
                    FullException   = ex.StackTrace
                });
                return(false);
            }
        }
예제 #16
0
        void SelectedTeam()
        {
            password = new PasswordLogin(teamSelected, (p) =>
            {
                token = p;
                AuthSignIn();
            });

            password.Dock = DockStyle.Fill;
            password.BackColor = Color.Transparent;

            Controls.Add(password);
            teams.Visible = false;
        }
예제 #17
0
파일: Logger.cs 프로젝트: Rishirakish/OSDP
 public async Task <int> PasswordChangeLog(PasswordLogin passwordLogin)
 {
     return(await Task.Run(() => _loggerRepository.PasswordChangeLog(passwordLogin)));
 }