Exemple #1
0
        public JsonResult SaveCommande(string s)
        {
            try
            {
                //decrypage de la SessionID et recherche dans la bdd
                string             IdSession          = Cryptage.Decrypt(s);
                SessionUtilisateur sessionUtilisateur = daoUtilisateur.GetSessionUtilisateur(IdSession);
                Panier             panier             = null;

                if (sessionUtilisateur != null && HttpContext.Application[sessionUtilisateur.IdSession] != null)
                {
                    panier = (Panier)HttpContext.Application[sessionUtilisateur.IdSession];
                }

                Utilisateur utilisateur = daoUtilisateur.GetUtilisateurBySessionId(sessionUtilisateur.IdSession);

                if (utilisateur != null && utilisateur.Solde > 0 && panier != null && panier.Count > 0)
                {
                    if (daoCommande.SaveCommande(panier, utilisateur))
                    {
                        HttpContext.Application.Remove(utilisateur.IdSession);
                    }
                }
                return(Json(new { idutilisateur = utilisateur.IdUtilisateur }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                string er = ex.Message;
            }
            return(Json(JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public ActionResult Create(CryptageModel submited)
        {
            var stopwatch = Stopwatch.StartNew();
            var crypt     = new Cryptage();

            Debug.WriteLine($"Creating hash for password '{ submited.password }'.");
            var salt = crypt.CreateSalt();

            Debug.WriteLine($"Using salt '{ Convert.ToBase64String(salt) }'.");
            var hash = crypt.HashPassword(submited.password, salt);

            Debug.WriteLine($"Hash is '{ Convert.ToBase64String(hash) }'.");
            Debug.WriteLine($"Process took { stopwatch.ElapsedMilliseconds / 1024.0 } s");
            stopwatch.Stop();
            stopwatch = Stopwatch.StartNew();
            Debug.WriteLine($"Verifying hash...");

            var success = crypt.VerifyHash(submited.password, salt, hash);

            Debug.WriteLine(success ? "Success!" : "Failure!");
            stopwatch.Stop();
            Debug.WriteLine($"Process took { stopwatch.ElapsedMilliseconds / 1024.0 } s");
            return(View("Index"));
            //Comment faire revenir le hash sur la page d'accueil?
        }
Exemple #3
0
        public JsonResult AddProduit(int p, string s)
        {
            string             IdSession          = Cryptage.Decrypt(s);
            SessionUtilisateur sessionUtilisateur = daoUtilisateur.GetSessionUtilisateur(IdSession);
            Panier             panier             = GetPanier(sessionUtilisateur.IdSession);
            bool isReturnOk = false;

            if (sessionUtilisateur != null && panier != null && p > 0)
            {
                ProduitPanier produitPanier = FindProduit(p);

                if (produitPanier != null)
                {
                    if (panier.IdRestaurant == 0)
                    {
                        panier.IdRestaurant = produitPanier.IdRestaurant;
                        panier.AddItem(produitPanier);
                        isReturnOk = true;
                    }

                    else if (panier.IdRestaurant == produitPanier.IdRestaurant)
                    {
                        panier.AddItem(produitPanier);
                        isReturnOk = true;
                    }
                }
                HttpContext.Application[sessionUtilisateur.IdSession] = panier;
            }

            string jsonPanier = Newtonsoft.Json.JsonConvert.SerializeObject(panier);

            return(Json(new { isReturnOk, qte = panier.Quantite, total = panier.Total, monpanier = jsonPanier }, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        /// <summary>
        /// Enregistre les identifiants dans le fichier de sauvegarde local du pc
        /// </summary>
        /// <param name="nom">Le nom d'utilisateur</param>
        /// <param name="password">Le mot de passe</param>
        public void Save(string nom, string password)
        {
            LocalOptions.SetOption(ChampNom, nom);
            LocalOptions.SetOption(ChampPassword, Cryptage.Crypt(password));

            LocalOptions.Enregistre();
        }
Exemple #5
0
        /// <summary>
        /// Pré-rempli les champs avec les données du locataire
        /// </summary>
        /// <param name="flatTextBoxNom">Textbox pour modifier le nom du locataire</param>
        /// <param name="flatTextBoxPassword">Textbox pour modifier le mot de passe du locataire</param>
        public async Task RempliChamps(FlatTextBox flatTextBoxNom, FlatTextBox flatTextBoxPassword)
        {
            LocataireReadDto locataireCourant = await _repositoryLocataires.LireId(Settings.IdLocataire);             // récupère le locataire dans la bdd

            // modifie les champs
            flatTextBoxNom.Text      = locataireCourant.Nom;
            flatTextBoxPassword.Text = Cryptage.Uncrypt(locataireCourant.Password);
        }
        public async void Add(string name, string password)
        {
            LocataireCreateDto locataireCreateDto = new LocataireCreateDto()
            {
                Nom      = name,
                Password = Cryptage.Crypt(password)
            };

            await _repositoryLocataires.Ajouter(locataireCreateDto);
        }
Exemple #7
0
        /// <summary>
        /// Update la bdd dse nouvelles informations de l'utilisateur
        /// </summary>
        /// <param name="nom">Nouveau nom du locataire</param>
        /// <param name="password">Nouveau mot de passe en clair du locataire</param>
        public async void Update(string nom, string password)
        {
            LocataireUpdateDto locataireUpdateDto = new LocataireUpdateDto()
            {
                Id       = Settings.IdLocataire,
                Nom      = nom,
                Password = Cryptage.Crypt(password)
            };

            await _repositoryLocataires.Modifier(locataireUpdateDto);
        }
Exemple #8
0
        /// <summary>
        /// Vérifie que les identifiants contenu sur le disque dur local sont valides avec la base de données
        /// </summary>
        /// <param name="controllerLocataires">Accès au contrôleur de gestion de la table Locataires de la bdd</param>
        /// <returns>true si les identifiants sont trouvés et valides, false sinon</returns>
        public async Task <bool> AuthInCacheValid(ControllerLocataires controllerLocataires)
        {
            (string, byte[])result = Get();

            if (result.Item1 != null && result.Item2 != null)
            {
                if (await controllerLocataires.Authentifie(result.Item1, Cryptage.Uncrypt(result.Item2)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #9
0
        public static string getCon_Config()
        {
            string res = "";

            try
            {
                string       file = HttpContext.Current.Server.MapPath("~/Config") + "/Config.dat";
                StreamReader sr   = new StreamReader(file);
                res = Cryptage.Decrypt(sr.ReadLine());
                sr.Close();
            }
            catch (Exception ex) {
                Configs.Debug(ex, "Omniyat.Models.TableGenerator.getCon_Config", "Echéc de chargement de Config/dat");
            }

            return(res);
        }
 private void btInscrire_Click(object sender, EventArgs e)
 {
     try
     {
         AdminController ac = new AdminController();
         if (txtPassword.Text.ToString().Equals(txtConfirmPassword.Text.ToString()))
         {
             Cryptage c = new Cryptage();
             ac.Inscrire(int.Parse(txtMatricule.Text.ToString()), txtLogin.Text.ToString(), c.Encrypt(txtPassword.Text.ToString()));
             this.Close();
         }
         else
         {
             MessageBox.Show("Vérifier le mot de passe", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error :" + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        /// <summary>
        /// Permet de savoir si les logs correspondent à ceux dans la base de données
        /// </summary>
        /// <param name="nom">Le nom du locataire</param>
        /// <param name="password">Le mot de passe du locataire</param>
        /// <returns>true si le nom et le mot de passe correspondent, false sinon</returns>
        public async Task <bool> Authentifie(string nom, string password)
        {
            LocataireReadDto locataire = await Existe(nom);

            if (locataire == null)
            {
                return(false);
            }

            _idValid = locataire.Id;

            using (StreamWriter file =
                       new StreamWriter(@"debug.txt", true))
            {
                await file.WriteLineAsync("1 - " + Encoding.ASCII.GetString(locataire.Password));

                await file.WriteLineAsync("2 - " + Encoding.ASCII.GetString(Cryptage.Crypt(password)));
            }

            return(locataire.Password.SequenceEqual(Cryptage.Crypt(password)));
        }
Exemple #12
0
        // GET: Sw

        public JsonResult AddMenu(int IdMenu, List <int> IdProduits, string s)
        {
            string             IdSession          = Cryptage.Decrypt(s);
            SessionUtilisateur sessionUtilisateur = daoUtilisateur.GetSessionUtilisateur(IdSession);
            Panier             panier             = GetPanier(sessionUtilisateur.IdSession);
            bool isReturnOk = false;

            if (sessionUtilisateur != null && panier != null && IdMenu > 0 && IdProduits.Count > 0)
            {
                Menu menu = daoMenu.GetMenuById(IdMenu);

                if (menu != null)
                {
                    MenuPanier menuPanier = new MenuPanier();
                    menuPanier.IdMenu   = IdMenu;
                    menuPanier.Prix     = menu.Prix;
                    menuPanier.Nom      = menu.Nom;
                    menuPanier.Quantite = 1;

                    foreach (int IdProduit in IdProduits)
                    {
                        ProduitPanier produitPanier = FindProduit(IdProduit);

                        if (produitPanier != null)
                        {
                            panier.IdRestaurant = produitPanier.IdRestaurant;
                            menuPanier.produits.Add(produitPanier);
                        }
                    }

                    panier.AddItem(menuPanier);
                    isReturnOk = true;
                }

                HttpContext.Application[sessionUtilisateur.IdSession] = panier;
            }
            string jsonPanier = Newtonsoft.Json.JsonConvert.SerializeObject(panier);

            return(Json(new { isReturnOk, qte = panier.Quantite, total = panier.Total, monpanier = jsonPanier }, JsonRequestBehavior.AllowGet));
        }
        public void  GenererLicence(string Datedebut, string NbreJour)
        {
            string _Licence;

            _Licence = Cryptage.Encrypt(Datedebut + "," + NbreJour);
            AuthentInitializeServiceClient client = new AuthentInitializeServiceClient();

            client.GenereLicenceCompleted += (ss, res) =>
            {
                if (res.Cancelled || res.Error != null)
                {
                    string error = res.Error.Message;
                    return;
                }

                if (res.Result == null)
                {
                    return;
                }
            };
            client.GenereLicenceAsync(_Licence);
        }
Exemple #14
0
        public static string getUrlServer()
        {
            string res = "";

            try
            {
                string       file = HttpContext.Current.Server.MapPath("~/Config") + "/Config.dat";
                StreamReader sr   = new StreamReader(file);
                res = Cryptage.Decrypt(sr.ReadLine());
                sr.Close();
            }
            catch (Exception ex)
            {
                Debug(ex);
            }
            ////res = @"Data Source=37.187.168.96\NEWSERVER;initial Catalog=TAM_LOG;Uid=softuser;Password=12345";  // SERVEUR
            ////res = @"Data Source=37.187.168.96\NEWSERVER;initial Catalog=TAM_DEV;Uid=softuser;Password=12345";
            //// res = @"Data Source=OMNIYAT-PC;Initial Catalog=TRDB_TAM;Password=softpass;User Id=softuser";//local
            //res = @"Data Source=192.168.0.21;Initial Catalog=TRDB_TAM;Password=softpass;User Id=softuser";

            return(res);
        }
        public void GenererChaineConnexion(string laChaine)
        {
            string _Licence;

            _Licence = Cryptage.Encrypt(laChaine);
            AuthentInitializeServiceClient client = new AuthentInitializeServiceClient();

            client.GenereLicenceCompleted += (ss, res) =>
            {
                if (res.Cancelled || res.Error != null)
                {
                    string error = res.Error.Message;
                    return;
                }

                if (res.Result == null)
                {
                    return;
                }
            };
            client.GenereLicenceAsync(_Licence);
        }