public async Task <ServerResponse <AuthorizationTokenResponse> > LoginAsync(LoginRequest request) { return(await BaseInvokeAsync(async() => { var appUser = await DbContext.AppUsers .AsQueryable() .FirstOrDefaultAsync(x => x.Username == request.UserName); if (appUser == null) { throw new UnauthorizedException(Constants.Errors.UsernameIsIncorrect); } if (!HashPasswordHelper.Verify(appUser.Password, request.Password)) { throw new UnauthorizedException(Constants.Errors.PasswordIsIncorrect); } var tokenInfo = _tokenService.CreateToken(GetClaimsFromAppUser(appUser)); var authorizationTokenResponse = new AuthorizationTokenResponse() { Token = tokenInfo.Token, ExpirationDate = tokenInfo.ExpiredDate, AppUserViewModel = Mapper.Map <AppUser, AppUserViewModel>(appUser) }; return ServerResponseBuilder.Build(authorizationTokenResponse); }, request)); }
public bool IsPasswordNew(string newPassword, int userId) { var unitOfWork = new UnitOfWork(new OasisContext()); var userPasswords = unitOfWork.GetBaseRepository <UserPassword>().GetAll(); return(userPasswords.All(userPassword => !HashPasswordHelper.VerifyHashedPassword(userPassword.PasswordHash, newPassword))); }
public async Task <AOResult <AuthorizationTokenResponse> > RegisterAsync(RegistrationRequest request) { return(await BaseInvokeAsync(async() => { if (_myHelperDbContext.AppUsers.Any(x => x.Email == request.Email || x.Username == request.UserName)) { return AOBuilder.SetError <AuthorizationTokenResponse>(Constants.Errors.UserAlreadyRegistered); } var appUser = new AppUser { Username = request.UserName, Email = request.Email, Password = HashPasswordHelper.Hash(request.Password), UserRole = EUserRole.User, CreatedDate = DateTime.Now }; await _myHelperDbContext.AddAsync(appUser); await _myHelperDbContext.SaveChangesAsync(); var tokenInfo = _tokenService.CreateToken(GetClaimsFromAppUser(appUser)); var authorizationTokenResponse = new AuthorizationTokenResponse() { Token = tokenInfo.Token, ExpirationDate = tokenInfo.ExpiredDate, AppUserViewModel = _mapper.Map <AppUser, AppUserViewModel>(appUser) }; return AOBuilder.SetSuccess(authorizationTokenResponse); }, request)); }
public async Task SignInAsync(ISignInRoomDTO dto) { var room = _roomRepository.GetAll(r => r.UniqName == dto.UniqName).FirstOrDefault(); if (room == null) { throw new RoomNotFoundException(); } if (room.UserRooms.Any(ur => ur.User.NormalizedUserName == _currentUserName)) { AddRoomToUserIdentity(dto.UniqName); return; } if (room.PasswordHash != HashPasswordHelper.GetPasswordHash(dto.Password)) { throw new IncorrectPasswordException(); } var user = await _userManager.FindByNameAsync(_currentUserName); room.UserRooms.Add(new UserRoom() { UserId = user.Id, RoomId = room.Id }); _roomRepository.Update(room); AddRoomToUserIdentity(dto.UniqName); }
public bool CheckOldPassword(string oldPassword, int userId) { var unitOfWork = new UnitOfWork(new OasisContext()); var userPasswordHash = unitOfWork.GetBaseRepository <User>().Get(userId).PasswordHash; return(HashPasswordHelper.VerifyHashedPassword(userPasswordHash, oldPassword)); }
public bool VerifyCredentials(string userName, string password) { var unitOfWork = new UnitOfWork(new OasisContext()); var user = unitOfWork.GetBaseRepository <User>() .GetAll(r => r.UserRoles) .SingleOrDefault(r => r.UserName == userName); return(user != null && HashPasswordHelper.VerifyHashedPassword(user.PasswordHash, password)); }
public void SaveUserPassword(string newPassword, int userId) { var unitOfWork = new UnitOfWork(new OasisContext()); var user = unitOfWork.GetBaseRepository <User>().Get(userId); user.PasswordHash = HashPasswordHelper.HashPassword(newPassword); SaveUserPasswordHistory(user.PasswordHash, userId, unitOfWork); unitOfWork.SaveChanges(); }
private MessageClass LogPayaNewPayInfor() { var bc = new MessageClass(); if (!string.IsNullOrEmpty(Convert.ToString(Session["InstitutionCode"]))) { var xpresspaytransId = HashPasswordHelper.GetUniqueKey(6); var newTransRefNo = "PAYREF" + xpresspaytransId; Session["newTransRefNo"] = newTransRefNo; var instutud = Convert.ToString(Session["InstitutionCode"]); var commandToExecute = new SqlCommand("Barsh.LogTransaction_InsertOrUpdate") { CommandType = CommandType.StoredProcedure }; commandToExecute.Parameters.AddWithValue("@TransRefNo", newTransRefNo); commandToExecute.Parameters.AddWithValue("@Surname", Session["dbSurname"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@OtherNames", Session["dbOtherNames"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@Address", Session["dbAddress"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@Email", Session["dbEmail"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@PhoneNo", Session["dbPhoneNo"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@RevenueName", Session["dbRevenueName"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@RevenueCode", Session["dbRevenueCode"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@AgencyName", Session["dbAgencyName"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@AgencyCode", Session["dbAgencyCode"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@AmountPaid", Convert.ToDecimal(Session["transDbAmount"].ObjectToString())); commandToExecute.Parameters.AddWithValue("@PayGateWay", Session["dbPayGateWay"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@institutionCode", instutud); commandToExecute.Parameters.AddWithValue("@CountryName", Session["dbCountryName"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@StateName", Session["dbStateName"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@LGA", Session["dbLGA"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@City", Session["dbCity"].ObjectToString()); commandToExecute.Parameters.AddWithValue("@Area", Session["dbArea"].ObjectToString()); var recCount = DataBaseHandler.ExecuteSqlCommand(commandToExecute); bc.StatusId = recCount > 0 ? 1 : 0; if (recCount > 0) { bc = Selectgateway(newTransRefNo); bc.StatusId = 1; } else { bc.StatusMessage = "Unable to fetch all logged transaction"; bc.StatusId = -1; } } else { bc.StatusMessage = "Invalid Merchant Code"; bc.StatusId = -1; } return(bc); }
public User Authenticate(string username, string password) { var user = _userRepository .GetWhere(x => x.Username == username && x.Password == HashPasswordHelper.HashPassword(password, x.Salt)).FirstOrDefault(); if (user == null) { return(null); } return(GenerateTokenForUser(user)); }
public int AddClinicUser(ClinicUser user) { bool uniqueUserName = CheckUserName(user.Username); bool uniqueUserIdNumber = CheckIDNumber(user.IDNumber); string password = HashPasswordHelper.HashPassword(user.Password); try { using (MedicaClinicEntities2 context = new MedicaClinicEntities2()) { if (user.ClinicUserId == 0 && uniqueUserName && uniqueUserIdNumber) { ClinicUser newClinicUser = new ClinicUser(); newClinicUser.FullName = user.FullName; newClinicUser.IDNumber = user.IDNumber; newClinicUser.GenderId = user.GenderId; newClinicUser.DateOfBirth = user.DateOfBirth; newClinicUser.Citizenship = user.Citizenship; newClinicUser.Username = user.Username; newClinicUser.IsDeleted = false; newClinicUser.RoleId = user.RoleId; newClinicUser.Password = password; context.ClinicUsers.Add(newClinicUser); context.SaveChanges(); user.ClinicUserId = newClinicUser.ClinicUserId; return(user.ClinicUserId); } else { ClinicUser editUser = (from p in context.ClinicUsers where p.ClinicUserId == user.ClinicUserId select p).First(); editUser.FullName = user.FullName; editUser.IDNumber = user.IDNumber; editUser.GenderId = user.GenderId; editUser.DateOfBirth = user.DateOfBirth; editUser.Citizenship = user.Citizenship; editUser.Username = user.Username; editUser.IsDeleted = false; editUser.RoleId = user.RoleId; editUser.ClinicUserId = user.ClinicUserId; context.SaveChanges(); return(user.ClinicUserId); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); Logging.LoggAction("MasterAminViewModel", "Error", ex.ToString()); return(0); } }
private MessageClass CheckAgencyExeception() { var messageClass = new MessageClass(); var cmdMyQuery = new SqlCommand("Barsh.Querr_CheckAgencyException") { CommandType = CommandType.StoredProcedure }; cmdMyQuery.Parameters.AddWithValue("@AgencyCode", LblAgencyID.Text); cmdMyQuery.Parameters.AddWithValue("@StateCode", LblMerchantCode.Text); var dtresponse = DataBaseHandler.SqlSelect(cmdMyQuery); var xpressResponseResult = Newtonsoft.Json.JsonConvert.SerializeObject(dtresponse); Console.WriteLine(dtresponse); if (dtresponse.Rows.Count > 0) { //Session["Payer"] = "Payer"; //Session["RevAgency"] = "RevAgency"; ////Session["RevException"] = string.Empty; //Session["agencyName"] = LblAgencyName.Text; //Session["agencyID"] = LblAgencyID.Text; //Session["revenueName"] = LblSelectedRevName.Text; //Response.Redirect("~/PayerSearch"); CheckRevenueExeception(); } else { Session["Payer"] = "Payer"; Session["RevException"] = string.Empty; Session["RevAgency"] = string.Empty; Session["agencyName"] = LblAgencyName.Text; Session["agencyID"] = LblAgencyID.Text; Session["revenueName"] = LblSelectedRevName.Text; Session["revenueID"] = LblSelectRevID.Text; Session["NoPayerRefNo"] = string.Empty; //var xpresspaytransId = HashPasswordHelper.GeneratePassword(10); var xpresspaytransId = HashPasswordHelper.GetUniqueKey(6); Session["transidno"] = "PAYREF" + xpresspaytransId; Session["url"] = LbluseUrl.Text; Session["DbGateWayID"] = LblDbGatewayName.Text; Session["StateName"] = LbluseUrl.Text; Session["StateCode"] = LblMerchantCode.Text; Response.Redirect("~/PayerDetails"); } return(messageClass); }
public User Authenticate(string email, string password) { var a = HashPasswordHelper.HashPassword(password); User mUser = new User(); mUser = userRepository.Authenticate(email); if (mUser != null && HashPasswordHelper.ValidatePassword(password, mUser.passwordHash)) { return(mUser); } else { return(null); } }
public Doctor LoginDoctor(string username, string password) { password = HashPasswordHelper.HashPassword(password); try { using (HospitalEntities5 context = new HospitalEntities5()) { Doctor doctor = (from d in context.Doctors where d.Username.Equals(username) where d.DoctorPassword.Equals(password) select d).First(); return(doctor); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public Patient AddPatient(Patient patient) { bool uniqueUser = CheckUserName(patient.Username); try { using (HospitalEntities5 context = new HospitalEntities5()) { if (patient.PatientId == 0) { if (uniqueUser) { Patient newPatient = new Patient(); newPatient.Fullname = patient.Fullname; newPatient.PatientJMBG = patient.PatientJMBG; newPatient.NumInsurce = patient.NumInsurce; newPatient.Username = patient.Username; newPatient.PatientPassword = HashPasswordHelper.HashPassword(patient.PatientPassword); context.Patients.Add(newPatient); context.SaveChanges(); patient.PatientId = newPatient.PatientId; } return(patient); } else { Patient editPatient = (from p in context.Patients where p.PatientId == patient.PatientId select p).First(); editPatient.Fullname = patient.Fullname; editPatient.PatientJMBG = patient.PatientJMBG; editPatient.NumInsurce = patient.NumInsurce; editPatient.Username = patient.Username; editPatient.DoctorId = patient.DoctorId; editPatient.PatientId = patient.PatientId; context.SaveChanges(); return(patient); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public Doctor AddDoctor(Doctor doctor) { bool uniqueUser = CheckUserName(doctor.Username); try { using (HospitalEntities5 context = new HospitalEntities5()) { if (doctor.DoctorId == 0) { if (uniqueUser) { Doctor newDoctor = new Doctor(); newDoctor.FullName = doctor.FullName; newDoctor.DoctorJMBG = doctor.DoctorJMBG; newDoctor.BankAccount = doctor.BankAccount; newDoctor.Username = doctor.Username; newDoctor.DoctorPassword = HashPasswordHelper.HashPassword(doctor.DoctorPassword); context.Doctors.Add(newDoctor); context.SaveChanges(); doctor.DoctorId = newDoctor.DoctorId; } return(doctor); } else { Doctor editDoctor = (from p in context.Doctors where p.DoctorId == doctor.DoctorId select p).First(); editDoctor.FullName = doctor.FullName; editDoctor.DoctorJMBG = doctor.DoctorJMBG; editDoctor.BankAccount = doctor.BankAccount; editDoctor.Username = doctor.Username; editDoctor.DoctorPassword = doctor.DoctorPassword; editDoctor.DoctorId = doctor.DoctorId; context.SaveChanges(); return(doctor); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public int AddHotelUser(HotelUser user) { string password = HashPasswordHelper.HashPassword(user.Password); try { using (HotelPremierEntities context = new HotelPremierEntities()) { if (user.HotelUserId == 0) { HotelUser newHotelUser = new HotelUser(); newHotelUser.FullName = user.FullName; newHotelUser.DateOfBirth = user.DateOfBirth; newHotelUser.Email = user.Email; newHotelUser.Username = user.Username; newHotelUser.RoleId = user.RoleId; newHotelUser.Password = password; context.HotelUsers.Add(newHotelUser); context.SaveChanges(); user.HotelUserId = newHotelUser.HotelUserId; return(user.HotelUserId); } else { HotelUser editUser = (from p in context.HotelUsers where p.HotelUserId == user.HotelUserId select p).First(); editUser.FullName = user.FullName; editUser.DateOfBirth = user.DateOfBirth; editUser.Email = user.Email; editUser.Username = user.Username; editUser.RoleId = user.RoleId; editUser.HotelUserId = user.HotelUserId; context.SaveChanges(); return(user.HotelUserId); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(0); } }
private void RedirectToPayement() { Session["Payer"] = "Payer"; Session["RevException"] = string.Empty; Session["RevAgency"] = string.Empty; Session["agencyName"] = LblAgencyName.Text; Session["agencyID"] = LblAgencyID.Text; Session["revenueName"] = LblSelectedRevName.Text; Session["revenueID"] = LblSelectRevID.Text; Session["NoPayerRefNo"] = string.Empty; //var xpresspaytransId = HashPasswordHelper.GeneratePassword(10); var xpresspaytransId = HashPasswordHelper.GetUniqueKey(6); Session["transidno"] = "PAYREF" + xpresspaytransId; Session["url"] = LbluseUrl.Text; Session["DbGateWayID"] = LblDbGatewayName.Text; Session["StateName"] = LbluseUrl.Text; Session["StateCode"] = LblMerchantCode.Text; Response.Redirect("~/PayerDetails"); }
public Patient LoginPatient(string username, string password) { password = HashPasswordHelper.HashPassword(password); try { using (HospitalEntities5 context = new HospitalEntities5()) { Patient patient = (from p in context.Patients where p.Username.Equals(username) where p.PatientPassword.Equals(password) select p).First(); return(patient); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public HotelUser LoginUser(string username, string password) { password = HashPasswordHelper.HashPassword(password); try { using (HotelPremierEntities context = new HotelPremierEntities()) { HotelUser user = (from d in context.HotelUsers where d.Username.Equals(username) where d.Password.Equals(password) select d).FirstOrDefault(); return(user); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public ClinicUser LoginUser(string username, string password) { password = HashPasswordHelper.HashPassword(password); try { using (MedicaClinicEntities2 context = new MedicaClinicEntities2()) { ClinicUser user = (from d in context.ClinicUsers where d.Username.Equals(username) where d.Password.Equals(password) where d.IsDeleted == false select d).FirstOrDefault(); return(user); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public async Task <AOResult <AuthorizationTokenResponse> > LoginAsync(LoginRequest request) { return(await BaseInvokeAsync(async() => { var appUser = await _myHelperDbContext.AppUsers .FirstOrDefaultAsync(x => x.Username == request.UserName); if (appUser == null || !HashPasswordHelper.Verify(appUser.Password, request.Password)) { return AOBuilder.SetError <AuthorizationTokenResponse>("Username or password is incorrect"); } var tokenInfo = _tokenService.CreateToken(GetClaimsFromAppUser(appUser)); var authorizationTokenResponse = new AuthorizationTokenResponse() { Token = tokenInfo.Token, ExpirationDate = tokenInfo.ExpiredDate, AppUserViewModel = _mapper.Map <AppUser, AppUserViewModel>(appUser) }; return AOBuilder.SetSuccess(authorizationTokenResponse); }, request)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { #region Relationships modelBuilder.Entity <Room>() .HasOne(r => r.PlayList) .WithOne(pl => pl.Room) .HasForeignKey <PlayList>(pl => pl.RoomId); modelBuilder.Entity <Room>() .HasMany(r => r.Messages) .WithOne(m => m.Room) .HasForeignKey(m => m.RoomId); modelBuilder.Entity <UserRoom>() .HasKey(ur => new { ur.RoomId, ur.UserId }); modelBuilder.Entity <UserRoom>() .HasOne(ur => ur.Room) .WithMany(r => r.UserRooms) .HasForeignKey(ur => ur.RoomId); modelBuilder.Entity <UserRoom>() .HasOne(ur => ur.User) .WithMany(u => u.UserRooms) .HasForeignKey(ur => ur.UserId); #endregion #region DataSeeding var user = new User() { Id = 1, UserName = "******", NormalizedUserName = "******".ToUpper() }; var user2 = new User() { Id = 2, UserName = "******", NormalizedUserName = "******".ToUpper() }; user.PasswordHash = new PasswordHasher <User>().HashPassword(user, "Password1"); user2.PasswordHash = new PasswordHasher <User>().HashPassword(user2, "Password1"); modelBuilder.Entity <User>() .HasData(user, user2); modelBuilder.Entity <IdentityRole <long> >() .HasData(new IdentityRole <long> { Id = 1, Name = "Admin", NormalizedName = "Admin".ToUpper() }); modelBuilder.Entity <UserRoom>() .HasData(new UserRoom() { RoomId = 1, UserId = 1 }); modelBuilder.Entity <Message>() .HasData(new Message() { Id = 1, DateSent = DateTime.UtcNow, RoomId = 1, UserId = 1, HashMessage = "SomeMessage" }); modelBuilder.Entity <Message>() .Property(m => m.DateSent) .HasDefaultValueSql("getutcdate()"); modelBuilder.Entity <Room>() .HasData(new Room() { Id = 1, Name = "Room1", UniqName = "UniqRoomNameAzaza", PasswordHash = HashPasswordHelper.GetPasswordHash("Password1") }); modelBuilder.Entity <PlayList>() .HasData(new PlayList() { Id = 1, RoomId = 1, TrackCurrentTime = new TimeSpan() }); #endregion base.OnModelCreating(modelBuilder); }
public void SeedDb() { if (_hostingEnvironment.IsEnvironment(Constants.HostEnvironment.Docker)) { _myHelperDbContext.Database.EnsureCreated(); } using (var transaction = _myHelperDbContext.Database.BeginTransaction()) { try { if (!_myHelperDbContext.AppUsers.Any(x => x.UserRole == EUserRole.Admin)) { var user = new AppUser { Email = "*****@*****.**", Username = "******", Password = HashPasswordHelper.Hash("admin"), UserRole = EUserRole.Admin, CreatedDate = DateTime.Now }; _myHelperDbContext.AppUsers.Add(user); _myHelperDbContext.SaveChanges(); } if (!_myHelperDbContext.Tags.Any() && !_myHelperDbContext.Notes.Any() && !_myHelperDbContext.NoteTags.Any()) { var note = new Note { Name = "Ef Core Migrations", Description = "1. dotnet ef migrations add name 2. dotnet ef database update", CreateDate = DateTime.Now, UpdateDate = DateTime.Now, AppUser = _myHelperDbContext.AppUsers.FirstOrDefault() }; var tags = new Tag[] { new Tag { Name = "entity framework" }, new Tag { Name = "migrations" } }; _myHelperDbContext.AddRange( new NoteTag { Note = note, Tag = tags[0] }, new NoteTag { Note = note, Tag = tags[1] } ); _myHelperDbContext.SaveChanges(); } transaction.Commit(); } catch { transaction.Rollback(); } } }
public RoomMappingProfile() { CreateMap <IAddRoomDTO, Room>() .ForMember(r => r.PasswordHash, opt => opt.MapFrom(dto => HashPasswordHelper.GetPasswordHash(dto.Password))); }
public void Add(User user) { user.Salt = HashPasswordHelper.GenerateSalt(); user.Password = HashPasswordHelper.HashPassword(user.Password, user.Salt); _userRepository.Add(user); }