begin process at 2010 07 30 12:53:22
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Sécurité & Cryptage

 > CLASS POUR LES LOGIN

CLASS POUR LES LOGIN


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Sécurité & Cryptage Source .NET ( DotNet ) Classé sous :XML-Login Class, Users XML-Class, Classe Utilisateur-EtMotDePasse Niveau :Débutant Date de création :22/11/2009 Date de mise à jour :25/01/2010 06:13:52 Vu :2 421

Auteur : DanMor498

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

// Une Classe qui peut être utiliser avec vos projets.
// il sagit d'un hacheur Pour Mot de passe  [ sha1encrypt ]
// d'un Encodeur / Décodeur de texte en sha512 [ GetEncryptedData | GetDecryptedData ]
// Et aussi le moyen de créer un fichier xml pour sauvegarder vos Nom Utilisateurs mot de passe encrypter
// a peut pres n'import-ou sur votre machine. et de vérifier votre mot de passe.


Source

  • using System.IO;
  • using System;
  • using System.Text;
  • using System.Data;
  • using System.Windows.Forms;
  • using System.Xml;
  • using System.Xml.XPath;
  • using System.Security.Cryptography;
  • namespace Login1
  • {
  • class users
  • {
  • public string UName = "admin";
  • public string UPassword = "admin";
  • public void CreateNewPWD()
  • {
  • XmlDocument docUserLogin = new XmlDocument();
  • string strFilename = Application.ProductName + ".xml";
  • string UserName = "admin";
  • string UPassword = Encrypt("admin");
  • //crée le fichier XML
  • docUserLogin.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<!-- Copyright Daniel Morais 2009 -->" + "<" + Application.ProductName + "> <Users><Name>" + UserName + "</Name> <Password>" + UPassword + "</Password> </Users> </" + Application.ProductName + ">");
  • docUserLogin.Save(strFilename);
  • MessageBox.Show("Utilisateur 'admin' et Mot de passe 'admin' " + "\r\n" +
  • "ont été créer pour permettre un premier accès au programme " + "\r\n" +
  • "Vous devriez les changés après l'ouverture du programme en cliquand sur " + "\r\n" +
  • "Changer le mot de passe.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
  • //Récupération des attributs d'un fichier
  • File.SetAttributes(strFilename, FileAttributes.Hidden);
  • }
  • public void SaveUPWord(string strUser, string strPassword)
  • {
  • XmlDocument docUserLogin = new XmlDocument();
  • string strFilename = Application.ProductName + ".xml";
  • try
  • {
  • File.Delete(strFilename);
  • //create the xml file
  • docUserLogin.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<!-- Copyright Daniel Morais 2009 -->" + "<" + Application.ProductName + "> <Users><Name>" + strUser + "</Name> <Password>" + Encrypt(strPassword) + "</Password> </Users> </" + Application.ProductName + ">");
  • docUserLogin.Save(strFilename);
  • File.SetAttributes(strFilename, FileAttributes.Hidden);
  • }
  • catch
  • {
  • MessageBox.Show("Une erreur s'est produite dans le programme, impossible de connecter a " + strFilename, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
  • return;
  • }
  • finally
  • {
  • MessageBox.Show("L'utilisateur et le mot de passe ont été changé avec succès.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
  • }
  • }
  • public void ReadUPWord()
  • {
  • string FILE_NAME = Application.ProductName + ".xml";
  • XPathDocument doc;
  • XPathNavigator nav;
  • XPathExpression expr;
  • XPathNodeIterator iterator;
  • //LoadXml(FILE_NAME);
  • doc = new XPathDocument(FILE_NAME);
  • nav = doc.CreateNavigator();
  • // Compile a standard XPath expression
  • expr = nav.Compile("/" + Application.ProductName + "/Users/Name");
  • iterator = nav.Select(expr);
  • while (iterator.MoveNext())
  • {
  • XPathNavigator nav1 = iterator.Current.Clone();
  • UName = nav1.Value;
  • }
  • expr = nav.Compile("/" + Application.ProductName + "/Users/Password");
  • iterator = nav.Select(expr);
  • while (iterator.MoveNext())
  • {
  • XPathNavigator nav2 = iterator.Current.Clone();
  • UPassword = nav2.Value;
  • }
  • }
  • public string Encrypt(string pwd)
  • {
  • UTF8Encoding encoder = new UTF8Encoding();
  • SHA1CryptoServiceProvider sha1hasher = new SHA1CryptoServiceProvider();
  • byte[] hashedDataBytes = sha1hasher.ComputeHash(encoder.GetBytes(pwd));
  • return byteArrayToString(hashedDataBytes);
  • }
  • private string byteArrayToString(byte[] inputArray)
  • {
  • StringBuilder output = new StringBuilder("");
  • for (int i = 0; i < inputArray.Length; i++)
  • {
  • output.Append(inputArray[i].ToString("X2"));
  • }
  • return output.ToString();
  • }
  • ///'******* Encrypt the Data *******
  • private string GetEncryptedData(string Data)
  • {
  • SHA512Managed shaM = new SHA512Managed();
  • Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)));
  • byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
  • string eNC_str = Convert.ToBase64String(eNC_data);
  • //GetEncryptedData = eNC_str;
  • return eNC_str;
  • }
  • ///'******* Decrypt the Data *******
  • private string GetDecryptedData(string Data)
  • {
  • byte[] dEC_data = Convert.FromBase64String(Data);
  • string dEC_Str = ASCIIEncoding.ASCII.GetString(dEC_data);
  • //GetDecryptedData = dEC_Str;
  • return dEC_Str;
  • }
  • }
  • }
using System.IO;
using System;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using System.Security.Cryptography;

namespace Login1
{
    class users
    {
        public string UName = "admin";
        public string UPassword = "admin";

        public void CreateNewPWD()
        {
            XmlDocument docUserLogin = new XmlDocument();
            string strFilename = Application.ProductName + ".xml";
            string UserName = "admin";
            string UPassword = Encrypt("admin");
            //crée le fichier XML
            docUserLogin.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<!-- Copyright Daniel Morais 2009 -->" + "<" + Application.ProductName + "> <Users><Name>" + UserName + "</Name> <Password>" + UPassword + "</Password> </Users> </" + Application.ProductName + ">");
            docUserLogin.Save(strFilename);
            MessageBox.Show("Utilisateur  'admin'  et Mot de passe  'admin' " + "\r\n" +
             "ont été créer pour permettre un premier accès au programme " + "\r\n" +
             "Vous devriez les changés après l'ouverture du programme en cliquand sur " + "\r\n" +
             "Changer le mot de passe.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //Récupération des attributs d'un fichier                  
            File.SetAttributes(strFilename, FileAttributes.Hidden);
        }

        public void SaveUPWord(string strUser, string strPassword)
        {
            XmlDocument docUserLogin = new XmlDocument();
            string strFilename = Application.ProductName + ".xml";
            try
            {
                File.Delete(strFilename);
                //create the xml file
                docUserLogin.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<!-- Copyright Daniel Morais 2009 -->" + "<" + Application.ProductName + "> <Users><Name>" + strUser + "</Name> <Password>" + Encrypt(strPassword) + "</Password> </Users> </" + Application.ProductName + ">");
                docUserLogin.Save(strFilename);
                File.SetAttributes(strFilename, FileAttributes.Hidden);
            }
            catch
            {
                MessageBox.Show("Une erreur s'est produite dans le programme, impossible de connecter a " + strFilename, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            finally
            {
                MessageBox.Show("L'utilisateur et le mot de passe ont été changé avec succès.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public void ReadUPWord()
        {
            string FILE_NAME = Application.ProductName + ".xml";
            XPathDocument doc;
            XPathNavigator nav;
            XPathExpression expr;
            XPathNodeIterator iterator;

            //LoadXml(FILE_NAME);
            doc = new XPathDocument(FILE_NAME);
            nav = doc.CreateNavigator();

            // Compile a standard XPath expression

            expr = nav.Compile("/" + Application.ProductName + "/Users/Name");
            iterator = nav.Select(expr);
            while (iterator.MoveNext())
            {
                XPathNavigator nav1 = iterator.Current.Clone();
                UName = nav1.Value;
            }
            expr = nav.Compile("/" + Application.ProductName + "/Users/Password");
            iterator = nav.Select(expr);
            while (iterator.MoveNext())
            {
                XPathNavigator nav2 = iterator.Current.Clone();
                UPassword = nav2.Value;
            }
        }

        public string Encrypt(string pwd)
        {
            UTF8Encoding encoder = new UTF8Encoding();
            SHA1CryptoServiceProvider sha1hasher = new SHA1CryptoServiceProvider();
            byte[] hashedDataBytes = sha1hasher.ComputeHash(encoder.GetBytes(pwd));
            return byteArrayToString(hashedDataBytes);
        }

        private string byteArrayToString(byte[] inputArray)
        {
            StringBuilder output = new StringBuilder("");
            for (int i = 0; i < inputArray.Length; i++)
            {
                output.Append(inputArray[i].ToString("X2"));
            }
            return output.ToString();
        }

        ///'******* Encrypt the Data *******
        private string GetEncryptedData(string Data)
        {
            SHA512Managed shaM = new SHA512Managed();
            Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)));
            byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
            string eNC_str = Convert.ToBase64String(eNC_data);
            //GetEncryptedData = eNC_str;
            return eNC_str;
        }

        ///'******* Decrypt the Data *******
        private string GetDecryptedData(string Data)
        {
            byte[] dEC_data = Convert.FromBase64String(Data);
            string dEC_Str = ASCIIEncoding.ASCII.GetString(dEC_data);
            //GetDecryptedData = dEC_Str;
            return dEC_Str;
        }


    }

}


 Conclusion

users objuser = new users();
Pour utiliser le hacheur - Encrypt(UPassword)
pour l'encodeur - rtftext.Text = GetEncryptedData(rtftext.Rtf)
pour le décodeur - rtftext.rtf = GetDecryptedData(rtftext.Text)
pour créer le fichier XML - CreateNewPWD() ;
pour le lire - ReadPWord() ;
Bien sure il va vous falloir utiliser vos propre mot et textbox pour vous facilité la tâche


 Historique

22 novembre 2009 18:47:51 :
Correction
25 janvier 2010 06:13:52 :
je me suis rendu compte qui manquait des ligne de codes

 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) CRYPTOGRAPHY
Source avec Zip Source .NET (Dotnet) PARAMETRE SETTINGS.SETTINGS DÉMO!!
Source avec Zip Source avec une capture Source .NET (Dotnet) DEMO_XML_BASE_DE_DONNÉES
Source avec Zip Source .NET (Dotnet) BASE DE DONNÉES EN XML
Source avec Zip Source avec une capture Source .NET (Dotnet) LOGIN (XML)

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) CRYPTOGRAPHY par DanMor498
Source .NET (Dotnet) MSA CRYPTAGE NON REVERSIBLE PAR MATRICE SEMI-ALÉATOIRE par yohan49
Source avec une capture Source .NET (Dotnet) CPRB CRIPTAGE PAR POSITION ALÉATOIRE DE CLOCK par yohan49
Source avec Zip Source avec une capture UTILITAIRES DE DÉCODAGE ET D'ENCODAGE par Warny
Source avec Zip Source avec une capture Source .NET (Dotnet) CALCUL D'EMPREINTES DE FICHIERS par lex35

Commentaires et avis

Commentaire de zakizaki7 le 29/11/2009 12:27:01 8/10

joli travail ,
Merci

Commentaire de DanMor498 le 29/11/2009 15:40:19

Merci Mohamed
comment ca va en Algerie.

a+

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Juillet 2010
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,593 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales