コード例 #1
0
ファイル: Authorization.cs プロジェクト: DDeveloperBG/Tasks
        public static Doctor LogIn(HospitalContext db, string email, string password)
        {
            var hashedEmail = SHA256_Encrypter.Encrypt(email);
            var hashedPass  = SHA256_Encrypter.Encrypt(password);

            var doctor = db.DoctorsAuthentications
                         .FirstOrDefault(x => x.HashsedEmail == hashedEmail && x.HashsedPass == hashedPass)
                         ?.Doctor;

            return(doctor);
        }
コード例 #2
0
ファイル: Authorization.cs プロジェクト: DDeveloperBG/Tasks
        public static void SignIn(HospitalContext db, string email, string password, Doctor doctor)
        {
            var hashedEmail = SHA256_Encrypter.Encrypt(email);

            var doctorAuth = db.DoctorsAuthentications
                             .FirstOrDefault(x => x.HashsedEmail == hashedEmail);

            if (doctorAuth != null)
            {
                throw new ArgumentException("There is already a doctor with this email!");
            }

            db.DoctorsAuthentications.Add(new DoctorsAuthentication
            {
                HashsedEmail = hashedEmail,
                HashsedPass  = SHA256_Encrypter.Encrypt(password),
                Doctor       = doctor
            });

            db.SaveChanges();
        }