예제 #1
0
        /// <summary>
        /// procedure de changement de password par l'utilisateur lui-même
        /// </summary>
        /// <param name="admUser"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <param name="confirmPassword"></param>
        public static bool ChangePassword(CsUtilisateur pUser, CsStrategieSecurite pSecurity, string oldPassword, string newPassword, string confirmPassword, bool TenirCompteAncienPwd)
        {
            //Verifier si le changement de mot de passe peut se faire par rapport à la stratégie
            //Durée Minimale Password
            if (pUser.INITUSERPASSWORD != null && !(bool)pUser.INITUSERPASSWORD && pSecurity.DUREEMINIMALEPASSWORD != 0)
            {
                if (pUser.DATEDERNIEREMODIFICATIONPASSWORD != null && ((DateTime)pUser.DATEDERNIEREMODIFICATIONPASSWORD).AddDays(Convert.ToDouble(pSecurity.DUREEMINIMALEPASSWORD)) > DateTime.Now)
                {
                    throw new Exception(Langue.MsgModPwd);
                }
            }

            if (TenirCompteAncienPwd)
            {
                if (pUser.PASSE != Cryptage.Encrypt(oldPassword)) //EncryptWithOutKey(oldPassword)
                {
                    throw new Exception(Langue.MsgErrAncPwd);
                }
            }

            if (newPassword != confirmPassword)
            {
                throw new Exception(Langue.MsgErrConfPwd);
            }



            if (pSecurity.NEPASCONTENIRNOMCOMPTE)
            {
                if (newPassword.ToLower().Contains(pUser.LOGINNAME.ToLower()))
                {
                    throw new Exception(Langue.MsgPwdCpt);
                }
            }

            pUser.PASSE            = Cryptage.GetPasswordToBeSaved(pSecurity, pUser.LIBELLE, newPassword);
            pUser.INITUSERPASSWORD = false;
            pUser.DATEDERNIEREMODIFICATIONPASSWORD = DateTime.Now;
            //new DBAdmUsers().Update(admUser);
            return(true);
        }
예제 #2
0
        public static int GetNombreJourAvantExpiration(CsUtilisateur pUser, CsStrategieSecurite pSecurity, bool pPasswordExpireJamais)
        {
            pPasswordExpireJamais = false;

            //AdmStrategieSecurite StrategieSecuriteActif = new DBAdmStrategieSecurite().GetActif();
            pPasswordExpireJamais = pSecurity.DUREEMAXIMALEPASSWORD == 0;
            if (pPasswordExpireJamais)
            {
                return(0);
            }

            Nullable <System.DateTime> DateExpiration = new Nullable <System.DateTime>();

            if (pUser.DATEDERNIEREMODIFICATIONPASSWORD != null)
            {
                DateExpiration = ((Nullable <System.DateTime>)pUser.DATEDERNIEREMODIFICATIONPASSWORD).Value.AddDays(Convert.ToDouble(pSecurity.DUREEMAXIMALEPASSWORD));
            }
            else
            if (pUser.DATECREATION != null)
            {
                DateExpiration = ((DateTime?)pUser.DATECREATION).Value.AddDays(Convert.ToDouble(pSecurity.DUREEMAXIMALEPASSWORD));
            }

            if (DateExpiration.Value <= DateTime.Now)
            {
                return(-1);
            }

            int nbJour = 0;

            while (DateExpiration >= DateTime.Now)
            {
                nbJour++;
                DateExpiration = DateExpiration.Value.AddDays(-1);
            }

            return(nbJour);
        }
예제 #3
0
        public static Status VerifierDonneesConnexion(string pLogin, string pPassword, CsStrategieSecurite pSecurite, CsUtilisateur pUser)
        {
            try
            {
                if (pUser == null)
                {
                    return(new Status(false, new Exception(Langue.MsgErrLogin)));
                }

                if (pUser.ESTSUPPRIMER.Value)
                {
                    return(new Status(false, new Exception("Votre compte a été supprimé, vous n'avez plus le droit d'utiliser le système.")));
                }
                //verifier si le matricule correspond au groupe admin
                if (pUser.EsADMIN)
                {
                    if (VerifierCorrespondancePasword(pUser, pPassword))
                    {
                        return(new Status(false, null));
                    }
                    else
                    {
                        return(new Status(false, new Exception(Langue.MsgErrPwd)));
                    }
                }

                // si le user courant n'est pas admin donc est soumi à un filtrage

                //vérifier si le compte est valide pour la période de validité
                if (pUser.MATRICULE != "99999" && (pUser.DATEDEBUTVALIDITE != null && ((DateTime)pUser.DATEDEBUTVALIDITE).Date > DateTime.Now.Date))
                {
                    return(new Status(false, new Exception(string.Format(Langue.MsgUtilPasValid, pUser.LOGINNAME, pUser.MATRICULE))));
                }

                if (pUser.MATRICULE != "99999" && (pUser.DATEFINVALIDITE != null && ((DateTime)pUser.DATEFINVALIDITE).Date < DateTime.Now.Date))
                {
                    return(new Status(false, new Exception(string.Format(Langue.MsgUtilPasValid2, pUser.LOGINNAME, pUser.MATRICULE))));
                }


                //Durée Maximale Password
                if (pUser.MATRICULE != "99999" && (pSecurite.DUREEMAXIMALEPASSWORD != 0 && pUser.DATEDERNIEREMODIFICATIONPASSWORD != null))
                {
                    if (((DateTime)pUser.DATEDERNIEREMODIFICATIONPASSWORD).AddDays(Convert.ToDouble(pSecurite.DUREEMAXIMALEPASSWORD)) < DateTime.Now)
                    {
                        return(new Status(false, new Exception(Langue.MsgPwdExpire)));
                    }
                }

                //Verifier si le compte est actif
                if (pUser.FK_IDSTATUS != (int)Global.StatusCompte.Actif)
                {
                    //Le compte n'est pas actif
                    if (pUser.FK_IDSTATUS == (int)Global.StatusCompte.Inactif)
                    {
                        return(new Status(false, new Exception(string.Format(Langue.MsgCptDesactiv, pUser.LOGINNAME, pUser.MATRICULE))));
                    }

                    if (pUser.FK_IDSTATUS == (int)Global.StatusCompte.Verrouille)
                    {
                        return(new Status(false, new Exception(string.Format(Langue.MsgCptVerrouil, pUser.LOGINNAME, pUser.MATRICULE))));
                    }

                    if (pUser.FK_IDSTATUS == (int)Global.StatusCompte.VerrouilleOuvertureSession)
                    {
                        return(new Status(false, new Exception(string.Format(Langue.MsgCptVerrouil, pUser.LOGINNAME, pUser.MATRICULE))));
                    }

                    if (pSecurite.DUREEVERROUILLAGECOMPTE == 0)
                    {
                        return(new Status(false, new Exception(string.Format(Langue.MsgCptVerrouil, pUser.LOGINNAME, pUser.MATRICULE))));
                    }

                    //Verifier la durée de verrouillage s'est écoulée
                    //Si c'est non
                    if (pUser.DATEDERNIERVERROUILLAGE != null && ((DateTime)pUser.DATEDERNIERVERROUILLAGE).AddMinutes(Convert.ToDouble(pSecurite.DUREEVERROUILLAGECOMPTE)) > DateTime.Now)
                    {
                        return(new Status(false, new Exception(string.Format(Langue.MsgCptVerrouil2, pUser.LOGINNAME, pUser.MATRICULE, pSecurite.DUREEVERROUILLAGECOMPTE))));
                    }

                    //si la durée de verrouillage s'est écoulée
                    pUser.DATEDERNIERVERROUILLAGE      = null;
                    pUser.NOMBREECHECSOUVERTURESESSION = 0;

                    //Verifier Correspondance du pasword saisi par le pUser
                    if (!VerifierCorrespondancePasword(pUser, pPassword, true))
                    {
                        return(new Status(true, new Exception(Langue.MsgErrPwd)));
                    }
                    else
                    {
                        return(new Status(true, null));
                    }

                    //dbAdmUsers.Update(user);
                    //  return ;
                }
                else
                {
                    //NombreMaximalEchecsOuvertureSession <>0
                    if (pSecurite.NOMBREMAXIMALECHECSOUVERTURESESSION == 0)
                    {
                        pUser.DATEDERNIERECONNEXION = DateTime.Now;
                        if (!VerifierCorrespondancePasword(pUser, pPassword, false))
                        {
                            pUser.DERNIERECONNEXIONREUSSIE = false;
                            return(new Status(true, new Exception(Langue.MsgErrPwd)));
                        }
                        pUser.DERNIERECONNEXIONREUSSIE = true;
                        return(new Status(true, null));
                        ///dbAdmUsers.Update(pUser);
                    }
                    else
                    {
                        //Si Derniere Connexion Reussie
                        if (pUser.DERNIERECONNEXIONREUSSIE == null || (bool)pUser.DERNIERECONNEXIONREUSSIE)
                        {
                            //if(pUser.InitUserPassword) // ajouter par HGB 22/10/2013

                            if (!VerifierCorrespondancePasword(pUser, pPassword, true))
                            {
                                pUser.DERNIERECONNEXIONREUSSIE = false;

                                if (pUser.NOMBREECHECSOUVERTURESESSION == null)
                                {
                                    pUser.NOMBREECHECSOUVERTURESESSION = 1;
                                }
                                else
                                {
                                    pUser.NOMBREECHECSOUVERTURESESSION = pUser.NOMBREECHECSOUVERTURESESSION + 1;
                                }


                                if (pUser.MATRICULE != "99999" && (pUser.NOMBREECHECSOUVERTURESESSION >= pSecurite.NOMBREMAXIMALECHECSOUVERTURESESSION))
                                {
                                    pUser.DATEDERNIERVERROUILLAGE = pUser.DATEDERNIERECONNEXION;
                                    pUser.FK_IDSTATUS             = (byte)Global.StatusCompte.VerrouilleOuvertureSession;
                                    return(new Status(true, new Exception(string.Format(Langue.MsgErrMaxEchecConct, pUser.LOGINNAME, pUser.MATRICULE))));
                                }
                                else
                                {
                                    return(new Status(true, new Exception(Langue.MsgErrPwd)));
                                }
                            }
                            else
                            {
                                pUser.NOMBREECHECSOUVERTURESESSION = 0;
                                pUser.DERNIERECONNEXIONREUSSIE     = null;

                                return(new Status(true, null));
                            }
                        }
                        else
                        {
                            //Verifier si DateDerniereConnexion + delai Reinitialisation < Now
                            if (pUser.DATEDERNIERECONNEXION == null || ((DateTime)pUser.DATEDERNIERECONNEXION).AddMinutes(Convert.ToDouble(pSecurite.REINITIALISERCOMPTEURVERROUILLAGECOMPTEAPRES)) < DateTime.Now)
                            {
                                //Si oui
                                if (!VerifierCorrespondancePasword(pUser, pPassword, true))
                                {
                                    pUser.DERNIERECONNEXIONREUSSIE = false;
                                    if (pUser.NOMBREECHECSOUVERTURESESSION == null)
                                    {
                                        pUser.NOMBREECHECSOUVERTURESESSION = 1;
                                    }
                                    else
                                    {
                                        pUser.NOMBREECHECSOUVERTURESESSION = pUser.NOMBREECHECSOUVERTURESESSION + 1;
                                    }


                                    if (pUser.MATRICULE != "99999" && (pUser.NOMBREECHECSOUVERTURESESSION >= pSecurite.NOMBREMAXIMALECHECSOUVERTURESESSION))
                                    {
                                        pUser.DATEDERNIERVERROUILLAGE = pUser.DATEDERNIERECONNEXION;
                                        pUser.FK_IDSTATUS             = (byte)Global.StatusCompte.VerrouilleOuvertureSession;
                                        return(new Status(true, new Exception(string.Format(Langue.MsgErrMaxEchecConct, pUser.LOGINNAME, pUser.MATRICULE))));
                                    }
                                    else
                                    {
                                        return(new Status(true, new Exception(Langue.MsgErrPwd)));
                                    }
                                }
                                else
                                {
                                    pUser.NOMBREECHECSOUVERTURESESSION = 0;
                                    pUser.DERNIERECONNEXIONREUSSIE     = null;

                                    return(new Status(true, null));
                                }
                            }
                            else
                            {
                                // Sinon
                                //Incrémenter le nombre d'échecs
                                if (pUser.NOMBREECHECSOUVERTURESESSION == null)
                                {
                                    pUser.NOMBREECHECSOUVERTURESESSION = 1;
                                }
                                else
                                {
                                    pUser.NOMBREECHECSOUVERTURESESSION = pUser.NOMBREECHECSOUVERTURESESSION + 1;
                                }

                                //Si le nombre d'échecs a atteint le nombre maxi d'échecs autorisé
                                if (pUser.MATRICULE != "99999" && (pUser.NOMBREECHECSOUVERTURESESSION >= pSecurite.NOMBREMAXIMALECHECSOUVERTURESESSION))
                                {
                                    pUser.DATEDERNIERVERROUILLAGE = pUser.DATEDERNIERECONNEXION;
                                    pUser.FK_IDSTATUS             = (byte)Global.StatusCompte.VerrouilleOuvertureSession;
                                    //dbAdmUsers.Update(pUser);
                                    return(new Status(true, new Exception(string.Format(Langue.MsgErrMaxEchecConct, pUser.LOGINNAME, pUser.MATRICULE))));
                                }
                                //Si le nombre maxi d'échecs autorisé n'est pas atteint
                                if (!VerifierCorrespondancePasword(pUser, pPassword, true))
                                {
                                    return(new Status(true, new Exception(Langue.MsgErrPwd)));
                                }
                                else
                                {
                                    return(new Status(true, null));
                                }
                            }
                        }
                    }
                }

                //return null;
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #4
0
        public static void StrategieDeMotDePasse(CsStrategieSecurite StrategieSecuriteActif, string UserDisplayName, string password)
        {
            //verifier que le password repond à la strategie (longueur minimale, complexité)
            //verifier que la longueur du password >= longueur minimale exigée
            if (password.Length < StrategieSecuriteActif.LONGUEURMINIMALEPASSWORD)
            {
                throw new Exception(string.Format(Langue.MsgLongPwd, StrategieSecuriteActif.LONGUEURMINIMALEPASSWORD));
            }

            Regex regex;

            //verifier que le password contient le Nombre minimal de Caractères majuscules anglais (A à Z)
            regex = new Regex(@"[A-Z]{1}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            if (regex.Matches(password).Count < StrategieSecuriteActif.NOMBREMINIMALCARACTERESMAJUSCULES)
            {
                throw new Exception(string.Format(Langue.MsgNbrMiniPwd, StrategieSecuriteActif.NOMBREMINIMALCARACTERESMAJUSCULES));
            }

            //verifier que le password contient le Nombre minimal de Caractères minuscules anglais (a à z)
            regex = new Regex(@"[a-z]{1}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            if (regex.Matches(password).Count < StrategieSecuriteActif.NombreMinimalCaracteresMinuscules)
            {
                throw new Exception(string.Format(Langue.MsgNbrMiniPwd2, StrategieSecuriteActif.NombreMinimalCaracteresMinuscules));
            }

            //verifier que le password contient le Nombre minimal de chiffres
            regex = new Regex(@"[0-9]{1}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            if (regex.Matches(password).Count < StrategieSecuriteActif.NOMBREMINIMALCARACTERESCHIFFRES)
            {
                throw new Exception(string.Format(Langue.MsgNbrMiniPwd3, StrategieSecuriteActif.NOMBREMINIMALCARACTERESCHIFFRES));
            }

            //verifier que le password contient le Nombre minimal de Caractères non alphanumeric
            regex = new Regex(@"\W{1}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            if (regex.Matches(password).Count < StrategieSecuriteActif.NOMBREMINIMALCARACTERENONALPHABETIQUES)
            {
                throw new Exception(string.Format(Langue.MsgNbrMiniPwd4, StrategieSecuriteActif.NOMBREMINIMALCARACTERENONALPHABETIQUES));
            }

            //Ne pas contenir le nom de compte de l’utilisateur ou des parties du nom complet de l’utilisateur
            //comptant plus de trois caractères successifs
            if (StrategieSecuriteActif.NEPASCONTENIRNOMCOMPTE)
            {
                string[] PartiesNom = UserDisplayName.Split(' ');
                //string[] PartiesNom = UserDisplayName.Split(char.Parse(" "));
                foreach (string _nom in PartiesNom)
                {
                    if (_nom.Length >= 4)
                    {
                        for (int i = 0; i <= _nom.Length - 4; i++)
                        {
                            regex = new Regex(_nom.Substring(i, 4) + "{1}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                            if (regex.IsMatch(password))
                            {
                                throw new Exception(Langue.MsgPwdCpt);
                            }
                        }
                    }
                }
            }
        }