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
|
protected void btnConnexion_Click(object sender, EventArgs e)
{
if (Authentifier(txtLogin.Text, txtPassword.Text))
{
//FormsAuthentication.SetAuthCookie(txtLogin.Text, true);
Params.getTableParams();
Session["UserID"] = txtLogin.Text;
//mettre tout les sessions à null sauf la session user!!!!
if (Session["UserID"] != null)
{
string save_userID = Session["UserID"].ToString();
Session.RemoveAll();
Session["UserID"] = save_userID;
PersonneConnecte.setUserID(Session["UserID"].ToString());
PersonneConnecte.setNomUS(procBD.getNomPersonne(Session["UserID"].ToString()));
PersonneConnecte.setPrenomUS(procBD.getPrenomPersonne(Session["UserID"].ToString()));
PersonneConnecte.setService(procBD.getService(Session["UserID"].ToString()));
PersonneConnecte.setNomPrenom1Lettre(procBD.getLibPersonne1Lettre(Session["UserID"].ToString()));
string admin = procBD.getSuperAdmin(Session["UserID"].ToString());
if (!string.IsNullOrEmpty(admin))
PersonneConnecte.setSuperAdmin(true);
else
PersonneConnecte.setSuperAdmin(false);
VariableGlobaleAction.nbActionDonnee = procBD.getNbActionDonnee(PersonneConnecte.getUserID());
VariableGlobaleAction.nbActionRecu = procBD.getNbActionRecu(PersonneConnecte.getUserID());
VariableGlobaleRD.nbRD = procBD.getNbRD(PersonneConnecte.getUserID());
LibelleChamp.InitLibChamp();
}
FormsAuthentication.RedirectFromLoginPage(txtLogin.Text, false);
}
else
{
lblMessage.Text = Resources.Dictionnaire.authentification;
}
}
private static string HashMD5(string chaine)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(chaine, "MD5");
}
private bool Authentifier(string strUtilisateur, string strMotDePasse)
{
bool bOk = false;
//strMotDePasse = FormsAuthentication.HashPasswordForStoringInConfigFile(strMotDePasse, "MD5");
DataAcces myFac = new DataAcces();
DbCommand cmd = myFac.CreateCommand("select * from UTILISATEUR where UserID='" + strUtilisateur + "'", myFac.GetConnection(), CommandType.Text);
try
{
DbDataReader drUtilisateur = myFac.ExecuteReader(cmd);
Cryptage2io MonCrypt = new Cryptage2io();
while (drUtilisateur.Read())
{
Response.Write(MonCrypt.CodeTexte(strMotDePasse, ""));
if (drUtilisateur["PASSWORD"].ToString() == MonCrypt.CodeTexte(strMotDePasse, ""))
{
bOk = true;
break;
}
}
drUtilisateur.Close();
}
catch (Exception e)
{
Response.Write("Erreur : " + e);
bOk = false;
}
return bOk;
} |
Partager