- 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;
}
}
}