Accueil > > > CLASS POUR LES LOGIN
CLASS POUR LES LOGIN
Information sur la source
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] AJOUTER DES IMAGES DANS LA MEDIA LIBRARY D'UN WINDOWS PHONE 7[WP7] AJOUTER DES IMAGES DANS LA MEDIA LIBRARY D'UN WINDOWS PHONE 7 par Audrey
L'émulateur Windows Phone 7, fourni avec la version Beta des outils développeurs n'inclut aucune image dans sa bibliothèque. Pas très pratique de tester son application lorsque l'on souhaite que l'utilisateur puisse choisir une image présente dans le télé...
Cliquez pour lire la suite de l'article par Audrey VIVE LES MOCKS ET LES POCOSVIVE LES MOCKS ET LES POCOS par vLabz
J'observe régulièrement autour de moi de la confusion à propos de ces deux termes et j'aimerais juste rappeler ce qu'ils signifient. Je ne suis bien sûr pas le mieux placé pour faire une leçon mais je vais faire de mon mieux pour mettre en valeur ce q...
Cliquez pour lire la suite de l'article par vLabz [WF4] WORKFLOW AND CUSTOM ACTIVITIES - BEST PRACTICES (4/5)[WF4] WORKFLOW AND CUSTOM ACTIVITIES - BEST PRACTICES (4/5) par JeremyJeanson
Vendredi dernier Microsoft a publié le quatrième épisode des bonnes pratiques pour coder ses activités custom dans WF4 : endpoint.tv - Workflow and Custom Activities - Best Practices (Part 4) . Tout comme pour les précédents épisodes, j'ai pris le temps d...
Cliquez pour lire la suite de l'article par JeremyJeanson DéVELOPPEMENT MOBILE : .NET COMPACT FRAMEWORK & LIMITATIONSDéVELOPPEMENT MOBILE : .NET COMPACT FRAMEWORK & LIMITATIONS par Pi-R
Introduction :
Le développement d'applications mobiles est quelque peu différent du développement d'applications sous Windows. En effet, le développement d'applications mobiles se base sur le .NET Compact Fra...
Cliquez pour lire la suite de l'article par Pi-R IPHONE VERSUS WP7 CODINGIPHONE VERSUS WP7 CODING par Nicolas
Je relais une présentation sur slideshare.net, qui compare le développement sur Iphone et Windows Phone 7, qui ma fait sourire. I phone versus windows phone 7 coding View more presentations from www.donburnett.com. J'aurais bien aimé une comparai...
Cliquez pour lire la suite de l'article par Nicolas
Forum
RE : OPC CLIENT RE : OPC CLIENT par djpattsouls
Cliquez pour lire la suite par djpattsouls OPC HELP??OPC HELP?? par djpattsouls
Cliquez pour lire la suite par djpattsouls
Logiciels
Crystal Report (11)CRYSTAL REPORT (11)Crystal Reports est un outil de reporting souple et puissant, vous pouvez très facilement consult... Cliquez pour télécharger Crystal Report Academy System (12.0.2.0)ACADEMY SYSTEM (12.0.2.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft iPod Vidéo Convertisseur 6 (6.0.3.0419)XILISOFT IPOD VIDéO CONVERTISSEUR 6 (6.0.3.0419)Xilisoft iPod Vidéo Convertisseur est un outil puissant de conversion d'iPod, facile à utiliser. ... Cliquez pour télécharger Xilisoft iPod Vidéo Convertisseur 6 Xilisoft iPhone Vidéo Convertisseur 6 (6.0.3.0419)XILISOFT IPHONE VIDéO CONVERTISSEUR 6 (6.0.3.0419)Xilisoft iPhone Vidéo Convertisseur est le meilleur logiciel de conversion iPhone qui peut facile... Cliquez pour télécharger Xilisoft iPhone Vidéo Convertisseur 6 Xilisoft iPad Vidéo Convertisseur 6 (6.0.3.0419)XILISOFT IPAD VIDéO CONVERTISSEUR 6 (6.0.3.0419)Il s'agit d'un logiciel polyvalent pour convertir les formats vidéo/audio populaires en formats p... Cliquez pour télécharger Xilisoft iPad Vidéo Convertisseur 6
|