-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginViewModel.cs
123 lines (108 loc) · 4.71 KB
/
LoginViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using CabinetMedical.ModeleDiagram;
using CabinetMedical.Views;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace CabinetMedical.ViewModel
{
public class LoginViewModel : ViewModelBase
{
CabinetMedicalContainer model = new CabinetMedicalContainer();
public ICommand Connexion { get; set; }
public User Utilisateur { get; set; }
private string pass { get; set; }
public string Pass
{
get { return pass; }
set
{
pass = value;
RaisePropertyChanged("Pass");
}
}
public LoginViewModel()
{
// Patients = new List<Patient>();
//Patient.DateNaiss = DateTime.Now;
Utilisateur = new User();
Connexion = new RelayCommand(ConnexionUtilisateur);
}
public void ConnexionUtilisateur()
{
Utilisateur.Password = Pass;
Boolean test = true;
// Utilisateur.Role= modele.RoleSet.Find(1);
Console.WriteLine(Utilisateur);
User uti = model.UserSet.Where(u => u.Login == Utilisateur.Login).SingleOrDefault();
Patient p = model.PatientSet.Where(u => u.LoginPatient == Utilisateur.Login).SingleOrDefault();
if (uti != null)
{
string savedPasswordHash = (model.UserSet.Where(u => u.Login == Utilisateur.Login).SingleOrDefault()).Password;
/* Extract the bytes */
byte[] hashBytes = Convert.FromBase64String(savedPasswordHash);
/* Get the salt */
byte[] salt = new byte[16];
Array.Copy(hashBytes, 0, salt, 0, 16);
/* Compute the hash on the password the user entered */
var pbkdf2 = new Rfc2898DeriveBytes(Utilisateur.Password, salt, 10000);
byte[] hash = pbkdf2.GetBytes(20);
/* Compare the results */
for (int i = 0; i < 20; i++)
{ if (hashBytes[i + 16] != hash[i]) test = false; }
if (!test) { MessageBox.Show("Ce Compte n'existe pas"); }
// User uti = model.UserSet.Where(u => u.Login == Utilisateur.Login && u.Password == Utilisateur.Password).SingleOrDefault();
//if(uti == null) { MessageBox.Show("Ce Compte n'existe pas"); }
else
{
Views.FenetreRendezVous X = new Views.FenetreRendezVous(uti.Role);
X.Show();
}
}
else if(p!=null)
{
string savedPasswordHash = (model.PatientSet.Where(u => u.LoginPatient == Utilisateur.Login).SingleOrDefault()).PasswordPatient;
/* Extract the bytes */
byte[] hashBytes = Convert.FromBase64String(savedPasswordHash);
/* Get the salt */
byte[] salt = new byte[16];
Array.Copy(hashBytes, 0, salt, 0, 16);
/* Compute the hash on the password the user entered */
var pbkdf2 = new Rfc2898DeriveBytes(Utilisateur.Password, salt, 10000);
byte[] hash = pbkdf2.GetBytes(20);
/* Compare the results */
for (int i = 0; i < 20; i++)
{ if (hashBytes[i + 16] != hash[i]) test = false; }
if (!test)
{
MessageBox.Show("Ce Compte n'existe pas");
FenetreConnexion fn = new FenetreConnexion();
fn.Show();
}
// User uti = model.UserSet.Where(u => u.Login == Utilisateur.Login && u.Password == Utilisateur.Password).SingleOrDefault();
//if(uti == null) { MessageBox.Show("Ce Compte n'existe pas"); }
else
{
Role r = new Role();
r.NomRole = "Patient";
r.RoleID = p.PatientID;
FenetreFichePatient X = new FenetreFichePatient(r);
X.Show();
}
}
else
{
MessageBox.Show("Veillez saisir des informations valides");
// FenetreConnexion fn = new FenetreConnexion();
//fn.Show();
}
}
}
}