private bool AddNewUserPassword(int userId, string password) { try { var vList = new User_Password { User_Id = userId, Password = GeneratePassword(password), AddedBy = userId, AddedOn = DateTime.Now }; adbContext.user_password.Add(vList); adbContext.SaveChanges(); return(true); } catch (Exception ex) { return(false); throw ex; } }
//Create new user_password & verify 5 password only which are not same public bool InsertPassword(int userId, string password) { try { if (!IsPasswordExist(userId, password)) { var vList = GetPasswordByUserId(userId); if (vList.Count() > 0) { var vCount = vList.OrderByDescending(w => w.AddedOn).Skip(PastPasswordVerify); adbContext.user_password.RemoveRange(vCount); adbContext.SaveChanges(); } var vUserPassword = new User_Password { User_Id = userId, Password = EncryptedPassword(password), AddedBy = userId, AddedOn = DateTime.Now }; adbContext.user_password.Add(vUserPassword); adbContext.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { return(false); throw ex; } }
private async void NextActivityPage() { CheckConnectionInternet.checkConnectivity(); if (string.IsNullOrEmpty(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Email.", "Accept"); return; } if (!IsValid(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter a real Email.", "Accept"); return; } var checkEmail = await App.MobileService.GetTable <User>().Where(p => p.Email == this.Email).ToListAsync(); if (checkEmail.Count > 0) { await Application.Current.MainPage.DisplayAlert( "Error", "This email has been registered.", "Try Another"); return; } if (string.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (this.Password.Length < 7) { await Application.Current.MainPage.DisplayAlert( "Error", "Your Password length must be greather than 6.", "Accept"); return; } if (string.IsNullOrEmpty(this.ReEnterPassword)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (!(Password.Equals(ReEnterPassword))) { await Application.Current.MainPage.DisplayAlert( "Error", "Passwords not match.", "Accept"); return; } if (!this.isReady) { await Application.Current.MainPage.DisplayAlert( "Error", "You must take a picture or select one", "Accept"); return; } this.IsRunning = true; CurrentUser.Email = Email; CurrentUser.IsActive = true; CurrentUser.Created_Date = DateTime.Now; byte[] encryted = System.Text.Encoding.Unicode.GetBytes(Password); var result = System.Convert.ToBase64String(encryted); int len = RandomId.length.Next(5, 10); User_Password password = new User_Password { Id = RandomId.RandomString(len), Password = result, User_Id_FK = CurrentUser.Id }; byteData = AzureStorage.Convert.ToByteArray(source); uploadedFilename = await AzureStorage.AzureStorage.UploadFileAsync(AzureStorage.ContainerType.Image, new MemoryStream(byteData)); string[] arr = source.Split('/'); File_Path filepath = new File_Path { Id = RandomId.RandomString(len), Type = "Image", Path = uploadedFilename, Filename = arr[arr.Length - 1], FileUrl = source, Saved_Date = DateTime.Today, User_Id_FK = CurrentUser.Id }; try { await App.MobileService.GetTable <Address>().InsertAsync(CurrentAddress); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <User>().InsertAsync(CurrentUser); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <User_Password>().InsertAsync(password); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <File_Path>().InsertAsync(filepath); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } /* * //logic azure upload blob * string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=lioncode;AccountKey=oY4jZN5nSf4g/4ATkgHIPAgjVRxF3fYS/R1BfhT1k9Li98e7vEYq4/DY4y38LHQ9zjvsvIXI8qEDYQWeeHbxHQ==;EndpointSuffix=core.windows.net"; * CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString); * CloudBlobClient blobClient = account.CreateCloudBlobClient(); * CloudBlobContainer blobContainer = blobClient.GetContainerReference("activitymaps"); * blobContainer.CreateIfNotExists(); * string sourcePath = this.source; * CloudBlockBlob destBlob = blobContainer.GetBlockBlobReference("activitymaps"); * * // Setup the number of the concurrent operations * TransferManager.Configurations.ParallelOperations = 64; * // Setup the transfer context and track the upload progress * SingleTransferContext context = new SingleTransferContext(); * // Upload a local blob * var task = TransferManager.UploadAsync( * sourcePath, destBlob, null, context, CancellationToken.None); * task.Wait(); */ this.IsRunning = false; MainViewModel.GetInstance().Login = new LoginViewModel(CurrentUser.Email); await Application.Current.MainPage.Navigation.PushAsync(new LoginPage()); }
//重置登录表单 private void Resetting_Button(object sender, RoutedEventArgs e) { User_Name.Clear(); User_Password.Clear(); }
private void picLocker_Click(object sender, EventArgs e) { if (Lock) // UnLock { if (txtUser.Text != "" && txtPass.Text != "") { var db = new LINQ_UserPassDataContext(); var arrAdmin = (from adminUser in db.User_Passwords where adminUser.UserName == @"#admin#" select adminUser).ToArray(); User_Password admin = new User_Password(); if (arrAdmin.Length > 0) admin = arrAdmin[0]; else return; string Password = CreateMD5Hash(txtPass.Text); if (txtUser.Text.ToLower() == admin.UserName.ToLower() && Password == admin.Password) { Lock = false; picLocker.Image = global::MakeClassSchedule.Properties.Resources.unlock; dgvUserPass.DataSource = db.User_Passwords; // dgvUserPass.Columns[0].HeaderText = "User Name"; dgvUserPass.Columns[0].Width = 120; dgvUserPass.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgvUserPass.Columns[0].ReadOnly = true; // dgvUserPass.Columns[1].HeaderText = "Password"; dgvUserPass.Columns[1].Width = 100; dgvUserPass.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; // dgvUserPass.Columns[2].HeaderText = "Password Hint"; dgvUserPass.Columns[2].Width = 100; // dgvUserPass.Columns[3].HeaderText = "Modifiers"; dgvUserPass.Columns[3].Width = 100; // this.Size = new Size(800, 300); } } } else // Lock { dgvUserPass.Columns.Clear(); dgvUserPass.Rows.Clear(); this.Size = new Size(300, 300); picLocker.Image = global::MakeClassSchedule.Properties.Resources._lock; txtUser.Text = string.Empty; txtPass.Text = string.Empty; txtRePass.Text = string.Empty; txtPassHint.Text = string.Empty; txtModifiers.Text = string.Empty; txtUser.Focus(); Lock = true; } }
private async void changePass() { var res = ""; var passwordQuerry = await App.MobileService.GetTable <User_Password>().Where(p => p.User_Id_FK == user[0].Id).ToListAsync(); if (passwordQuerry.Count > 0) { byte[] decryted = System.Convert.FromBase64String(passwordQuerry[0].Password); res = System.Text.Encoding.Unicode.GetString(decryted); } if (string.IsNullOrEmpty(this.CurrentPassword)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (!res.Equals(this.CurrentPassword)) { await Application.Current.MainPage.DisplayAlert( "Error", "Its not your current password.", "Try Again"); return; } if (string.IsNullOrEmpty(this.NewPassword)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (this.NewPassword.Length < 7) { await Application.Current.MainPage.DisplayAlert( "Error", "Your Password length must be greather than 6.", "Accept"); return; } if (!(NewPassword.Equals(ReEnterPassword))) { await Application.Current.MainPage.DisplayAlert( "Error", "Passwords not match.", "Accept"); return; } byte[] encryted = System.Text.Encoding.Unicode.GetBytes(NewPassword); var result = System.Convert.ToBase64String(encryted); User_Password password = new User_Password { Id = passwordQuerry[0].Id, Password = result, User_Id_FK = user[0].Id }; await App.MobileService.GetTable <User_Password>().UpdateAsync(password); }
private async void setPassword() { this.IsRunning = true; var passwordQuerry = await App.MobileService.GetTable <User_Password>().Where(p => p.User_Id_FK == userQuery[0].Id).ToListAsync(); if (string.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); this.IsRunning = false; return; } if (this.Password.Length < 7) { await Application.Current.MainPage.DisplayAlert( "Error", "Your Password length must be greather than 6.", "Accept"); this.IsRunning = false; return; } if (!(Password.Equals(RePassword))) { await Application.Current.MainPage.DisplayAlert( "Error", "Passwords not match.", "Accept"); this.IsRunning = false; return; } byte[] encryted = System.Text.Encoding.Unicode.GetBytes(Password); var result = System.Convert.ToBase64String(encryted); User_Password password = new User_Password { Id = passwordQuerry[0].Id, Password = result, User_Id_FK = userQuery[0].Id }; await App.MobileService.GetTable <User_Password>().UpdateAsync(password); await Application.Current.MainPage.DisplayAlert( "Done", "Password has been changed.", "Accept"); this.ThirdButton = false; this.IsRunning = false; MainViewModel.GetInstance().Login = new LoginViewModel(this.Email); await Application.Current.MainPage.Navigation.PushAsync(new LoginPage()); }