Example #1
0
        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();
        }
        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));
        }
Example #3
0
        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);
            }
        }
        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);
            }
        }
Example #8
0
        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);
            }
        }
 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);
     }
 }
Example #10
0
 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);
     }
 }
Example #11
0
 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);
     }
 }
Example #12
0
 public void Add(User user)
 {
     user.Salt     = HashPasswordHelper.GenerateSalt();
     user.Password = HashPasswordHelper.HashPassword(user.Password, user.Salt);
     _userRepository.Add(user);
 }