/// <summary> /// Attempts to log the user in /// </summary> /// <param name="parameter"></param> /// <returns>SecureString passed in from the view</returns> public async Task LoginAsync(IHavePassword parameter) { await RunCommandAsync(() => this.LoginIsRunning, async() => { // Call the database LoginResultDataModel result = await IoC.ClientDataStore.CheckLoginAsync(new LoginCredentialsDataModel { Email = Email, Password = parameter.SecurePassword.Unsecure(), }); // if the response has an error -> display it if (result == null) { // done await IoC.UI.ShowMessageBoxDialog(new DialogMessageBoxViewModel { Message = "Login Failed" }, "Login failed!"); return; } // if we got here -> successfully logged in IoC.ApplicationViewModel.MasterHash = Crypt.Hash(parameter.SecurePassword.Unsecure()); // let the application view model what happens on the successful login IoC.ApplicationViewModel.HandleSuccessfulLogin(result); }); }
/// <summary> /// 用户名改变时 /// </summary> /// <param name="Login"></param> private void UsernameChanged(IHavePassword Login) { IsRememberPwd = false;//设置为空 Task.Run(() => { var list = new LocalUser().GetAllList().Where(d => d.Telephone == UserId); if (list.Count() > 0 && !string.IsNullOrWhiteSpace(list.First().Password)) { int pwdLength = 0; if (int.TryParse(list.First().PasswordLength.ToString(), out pwdLength) && pwdLength > 0) { App.Current.Dispatcher.Invoke(() => { if (TruePasswordWhenRemembered != null) { Login.LoginSecurePassword = TruePasswordWhenRemembered.Substring(0, pwdLength).ToSecureString(); IsRememberPwd = true; } }); } } else { // if (TruePasswordWhenRemembered.StartsWith(UserId)) // { // App.Current.Dispatcher.Invoke(() => // { // Login.LoginSecurePassword = null; // IsRememberPwd = false; // }); // } } }); }
private async void loginAsync(IHavePassword parameter) { loading = true; informationText = ""; try { UserDTO user = null; await Task.Run(() => (user = login(parameter))); if (user != null) { //Set the user of the program _navigationService.user = user; //Navigate to a page according to their employee type if (user.EmployeeType.Equals("Manager")) { _navigationService.NavigateTo("ManagerView"); } else if (user.EmployeeType.Equals("Supervisor")) { _navigationService.NavigateTo("SupervisorView", true); } } } catch (Exception e) { informationText = e.Message; } finally { loading = false; } }
private void OnLogin(object arg) { IHavePassword passwordContainer = arg as IHavePassword; if (passwordContainer != null) { LoginDialogViewModel dialogViewModel = container.Resolve <LoginDialogViewModel>(); dialogViewModel.Title = "hallo"; dialogViewModel.Password = passwordContainer.Password; dialogViewModel.UserName = userName; dialogViewModel.EMail = null; this.showLoginDialogRequest.Raise( dialogViewModel, finishCall => { if (dialogViewModel.Result == null) { Message = string.Empty; } else if (dialogViewModel.Result.Equals(string.Empty)) { eventAggregator.GetEvent <CloseStartDialogEvent>().Publish(true); } else { Message = dialogViewModel.Result; } }); } }
/// <summary> /// The process of login /// </summary> private async Task LoginAsync(IHavePassword control) { try { this.IsButtonEnabled = false; if (this.SuccessMessage != null) { this.SuccessMessage = null; } // create UserDTO navigation parameter NavigationParameters navigationParameters = new NavigationParameters { { "UserDataChanged", true }, { "User", await _authService.LoginAsync("Mechanic", this.Username, control.Password) } }; // navigate to home page this._navigation.NavigateTo("Reservations", navigationParameters); this._navigation.NavigateToWithinNavbarRegion("Navbar"); } catch (Exception ex) { this.ErrorMessage = ex.Message; } finally { IsButtonEnabled = true; } }
private void ExecuteConfirm(IHavePassword havePassword) { _employeeService.Insert( LoginName, FirstName, LastName, havePassword.SecurePassword.Unsecure(), EmployeeRole); base.OnWindowCloseRequested(); }
private void UserLogin(IHavePassword parameter) { Task.Run(() => { if (IsVisitorLogin == true)//游客登录 { Applicate.URLDATA.data.apiUrl = ConfigurationUtil.GetValue("InitialServer") + "/"; VisitorKey = ConfigurationUtil.GetValue("InitialServer_key"); int index = VisitorKey.LastIndexOf("?"); VisitorKey = VisitorKey.Substring(index + 1); int index2 = VisitorKey.LastIndexOf("="); VisitorKey = VisitorKey.Substring(index2 + 1); VisitorLogin(); return; } //接收用户名和密码 string password; if (IsRememberPwd && TruePasswordWhenRemembered != null && !IsCancelRememberPwdAndTextNewPwd) //如果当前处于记住有效密码 且 不为加载密码后重新输入的密码 { password = TruePasswordWhenRemembered; //使用数据库密码 //parameter.LoginSecurePassword = TruePasswordWhenRemembered.ToSecureString(); } else//没记住密码 或 { password = parameter.LoginSecurePassword.UnSecure();//使用文本框内密码 } EnabledLogin = false;//暂时禁用登录 //获取经纬度 string Longitude = "0"; string Latitude = "0"; if (Location.IsUnknown != true) { Longitude = Location.Longitude.ToString(); Latitude = Location.Latitude.ToString(); } try { var client = ShiKuManager.ShiKuLogin(UserId, password, Latitude, Longitude, GobalAreaList[SelectedCountryCode].prefix.ToString()); client.UploadDataCompleted += LoginComplete; } catch (Exception ex) { SnackBar.Enqueue("登录失败:" + ex.Message, "重试", () => { LoginCommand.Execute(Applicate.GetWindow <IHavePassword>()); }); Console.WriteLine("登录失败:" + ex.Message); EnabledLogin = true;//启用登录 } }); }
private void ExecuteLogin(IHavePassword passwordHolder) { if (_loginService.LoginEmployee(LoginName, passwordHolder.SecurePassword.Unsecure())) { IncorrectLoginMessageVisible = false; _navigationService.ShowWindow(WindowType.MainWindow); base.OnWindowCloseRequested(); return; } IncorrectLoginMessageVisible = true; }
/// <summary> /// To validate user credential for login /// </summary> /// <param name="hasPassword"></param> async private void DoLogin(IHavePassword hasPassword) { try { var token = await BankerApiService.GetBankerTokenAsync(UserId, hasPassword.Password); var roles = await BankerApiService.GetRolesAsync(); UserId = roles.First(); } catch (Exception ex) { } }
private async void Login(IHavePassword parameter) { try { if (IsSigningIn) { return; } IsSigningIn = true; ErrorMessage = string.Empty; var userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync( new Uri(_portalUrl), UserName, ConvertToUnsecureString(parameter.Password)); //TODO: if remember me is checked, save creadentials to the Windows Credential Vault // Make sure that the credentials are saved for later use if (!AuthenticationManager.Current.Credentials.Contains(userCredentials)) { AuthenticationManager.Current.AddCredential(userCredentials); } var portal = await ArcGISPortal.CreateAsync(new Uri(_portalUrl), userCredentials, CancellationToken.None); ApplicationServices.EventAggregator.GetEvent <UserSessionCreatedEvent>().Publish( new UserSessionCreatedMessage(portal)); var parameters = new NavigationParameters { { "portal", portal } }; ApplicationServices.NavigationService.RequestNavigation("GroupSelectionView", parameters); } catch (ArcGISWebException ex) { ErrorMessage = ex.Details.First(); } catch (Exception ex) { Debug.WriteLine(ex); ErrorMessage = "Authentication failed due unexpected error."; } finally { IsSigningIn = false; parameter.ClearPassword(); } }
/// <summary> /// Function for attempting to log in the user /// </summary> /// <param name="parameter"> Password Box </param> /// <returns> returns the user information needed for the program </returns> private UserDTO login(IHavePassword parameter) { PasswordHelper passwordHelper = new PasswordHelper(); if (parameter != null) { //Grab the Secure String from the password container object var secureString = parameter.Password; if (string.IsNullOrWhiteSpace(email)) { informationText = "Enter your email"; } else if (secureString.Length == 0) { informationText = "Enter your password"; } else { //Grab the User DTO data UserLoginCredentialsDTO userDTO = _serviceProxy.GetUserLoginCredentials(email); if (userDTO == null) { informationText = "User does not exist"; return(null); } //Unsecure the password object and compare against the database salt and password hash if (userDTO.PasswordHash == passwordHelper.GenerateSHA256String(passwordHelper.ConvertToUnsecureString(secureString) + userDTO.Salt)) { //login success try { return(_serviceProxy.GetUser(email)); } catch (Exception e) { informationText = "There was a problem accessing the database"; Console.WriteLine(e); } } else { informationText = "Incorrect password"; } } } return(null); }
private async Task <bool> TryAuthenticate(IHavePassword model) { if (IsAsync) { if (RequestAuthenticateAsync != null) { return(await this.RequestAuthenticateAsync(model)); } } else { return(this.RequestAuthenticate(model)); } return(false); }
private async void createAccountAsync(IHavePassword parameter) { loading = true; informationText = ""; try { await Task.Run(() => createAccount(parameter)); } catch (Exception e) { informationText = e.Message; } finally { loading = false; } }
public void Setup() { _navigatorService = A.Fake <INavigatorService>(); _dialogs = A.Fake <IDialogManager>(); _passwordManager = A.Fake <IPasswordManager>(); _appSetttings = A.Fake <WikiUpload.Properties.IAppSettings>(); _password = A.Fake <IHavePassword>(); _fileUploader = A.Fake <IFileUploader>(); _helpers = A.Fake <IHelpers>(); _model = new LoginViewModel(_fileUploader, _navigatorService, _dialogs, _passwordManager, _helpers, _appSetttings); }
/// <summary> /// 用户注册 /// </summary> /// <param name="parameter">包含密码的Login对象</param> private void UserRegisterAccount(IHavePassword parameter) { if (UploadfilePath == null) { SnackBar.Enqueue("请选择头像!"); return; } if (rNickname == null || rNickname.Trim() == "") { SnackBar.Enqueue("昵称不能为空!"); return; } if (parameter.FirstRegisterSecurePassword.UnSecure().Length < 6) { SnackBar.Enqueue("密码长度不能小于6位!"); return; } if (parameter.FirstRegisterSecurePassword.UnSecure() != parameter.FinalRegisterSecurePassword.UnSecure()) { SnackBar.Enqueue("两次输入密码不一致!"); return; } /* * else if (string.IsNullOrEmpty(AvatorPath)) * { * SnackBar.Enqueue("请选择需要上传的头像!"); * return; * } */ HttpClient client = APIHelper.RegisterAccountAsync( PhoneNumber, GobalAreaList[RSelectedCountryCode].prefix.ToString(), parameter.FinalRegisterSecurePassword.UnSecure(), RNickname, gender, Helpers.DatetimeToStamp(BornDate), SelectedCountry, SelectedProvince, SelectedCity, SelectedArea); EnabledRegister = false;//暂时禁用控件 //指定注册成功事件 client.UploadDataCompleted += RegisterComplete; }
public Task <bool> ConnectAsync(string server, string mail, IHavePassword password) { return(Task.Run(() => { bool success = true; Client = new Pop3Client(); try { Client.Connect(server, 995, true); Client.Authenticate(mail, password.SecurePassword.Unsecure()); } catch { success = false; } return success; })); }
private bool CanLogin(object arg) { IHavePassword passwordContainer = arg as IHavePassword; if (passwordContainer != null) { string unsecureString = SecureStringConverter.ConvertToUnsecureString(passwordContainer.Password); if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(unsecureString)) { Message = string.Empty; return(true); } else { Message = "Füllen sie alle Felder aus"; return(false); } } else { return(false); } }
//TODO: Extract this procedure using LINQ expression (Episode 10) /// <summary> /// Simulate a login scenario with remote server verifying password /// </summary> /// <param name="havePasswordObject"></param> /// <returns></returns> private async Task Login(IHavePassword havePasswordObject) { var length = havePasswordObject.Password.Length; if (!CanLogin) { return; } CanLogin = false; try { await Task.Delay(5000); throw new NullReferenceException(); } catch { } finally { CanLogin = true; } }
public void Dispose() { if (password != null) { password.Dispose(); password = null; } if (loginCommand != null) { var disposable = loginCommand as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Creates a new user /// </summary> /// <param name="parameter"> Password Box </param> private void createAccount(IHavePassword parameter) { PasswordHelper passwordHelper = new PasswordHelper(); if (parameter != null) { //Grab the Secure String from the password container object var secureString1 = parameter.Password; var secureString2 = parameter.ConfirmPassword; if (string.IsNullOrWhiteSpace(email)) { informationText = "Enter an email"; } else if (string.IsNullOrWhiteSpace(firstName)) { informationText = "Enter a first name"; } else if (string.IsNullOrWhiteSpace(lastName)) { informationText = "Enter a last name"; } else if (string.IsNullOrWhiteSpace(employeeType)) { informationText = "Select an employee type"; } else if (secureString1.Length == 0) { informationText = "Enter your password"; } else if (secureString2.Length == 0) { informationText = "Confirm your password"; } else { try { if (_serviceProxy.checkDuplicateUser(email)) { informationText = "This email already has an account"; } else if (!passwordHelper.ConvertToUnsecureString(secureString1).Equals(passwordHelper.ConvertToUnsecureString(secureString2))) { informationText = "Passwords do not match"; } else { byte[] salt = getSalt(32); User user = new User { Email = email, FirstName = firstName, LastName = lastName, EmployeeType = employeeType, Salt = salt, PasswordHash = passwordHelper.GenerateSHA256String(passwordHelper.ConvertToUnsecureString(secureString1) + salt) }; _serviceProxy.addUser(user); informationText = "User added"; } } catch (Exception e) { informationText = "There was a problem accessing the database"; Console.WriteLine(e); } } } }