public bool ChangeNick(string oldnick, string newnick, byte[] newnickhashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(oldnick); if (user != null) //si l'utilisateur actuel existe { if (instance.SearchNick(newnick) == null) //si le nouveau login choisi est bon { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(newnick), newnickhashed)) //verification de la provenance du message { instance.RemoveUser(user); user.Login = newnick; instance.AddUser(user); instance.Serialiser(); result = true; } } } return result; }
public bool ChangeNick(string oldnick, string newnick, byte[] newnickhashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(oldnick); if (user != null) //si l'utilisateur actuel existe { if (instance.SearchNick(newnick) == null) //si le nouveau login choisi est bon { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(newnick), newnickhashed)) //verification de la provenance du message { instance.RemoveUser(user); user.Login = newnick; instance.AddUser(user); instance.Serialiser(); result = true; } } } return(result); }
public bool SendPrivateMessage(string nick, string recipient, string message, byte[] messagehashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); //on verifie que l'auteur existe if (user != null) { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(message), messagehashed)) //on verifie la provenance du message { Message news = new Message(nick, message); User todeliver = instance.SearchNick(recipient); //on verifie la presence du destinataire if (todeliver != null) { Message privatemessage = new Message(nick, message); instance.RemoveUser(todeliver); todeliver.AddPrivateMessage(privatemessage); instance.AddUser(todeliver); instance.Serialiser(); result = true; } } } return(result); }
public bool LogIn(string nick, string password, byte[] nickhashed, int counter, byte[] G, byte[] J, byte[] P, byte[] Q, byte[] Seed, byte[] X, byte[] Y) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); if (user != null) //si l'utilisateur existe { if (user.CheckPassword(password)) //si le mot de passe de l'utilisateur est bon { DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); DSAParameters key = Security.RecreateKey(counter, G, J, P, Q, Seed, X, Y); mycrypto.ImportParameters(key); ASCIIEncoding encoding = new ASCIIEncoding(); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verification de la cle publique recue { result = true; instance.RemoveUser(user); user.Publickey = key; //on stocke la cle publique pour la reception prochaine de message instance.AddUser(user); instance.Serialiser(); } } } return(result); }
public Message[] ReceiveMessageNonRead(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); Message[] unread = null; if (user != null) //on verifie si l'utilisateur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //on verifie la provenance de la demande { //requete LINQ pour recuperer les messages a lire unread = (from Message m in instance.Messages where m.Creation > user.LastRead select m).ToArray <Message>(); instance.RemoveUser(user); user.LastRead = DateTime.Now; //on modifie la date de derniere lecture instance.AddUser(user); instance.Serialiser(); } } return(unread); }
public Message[] ReceivePrivateMessage(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); Message[] privatemessage = null; if (user != null) //si l'utilisateur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verification de la provenance du message { privatemessage = user.PrivateMessage.ToArray <Message>(); } } return(privatemessage); }
public Message[] ReceiveAllMessage(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); Message[] message = null; User user = instance.SearchNick(nick); if (user != null) //on verifie si le demandeur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //on verifie la provenance de la demande { message = instance.Messages.ToArray <Message>(); } } return(message); }
public bool SendMessage(string nick, string message, byte[] messagehashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); //verification de l'utilisateur if (user != null) { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(message), messagehashed)) //on verifie que le message provient bien de l'utilisateur { Message news = new Message(nick, message); instance.AddMessage(news); instance.Serialiser(); result = true; } } return(result); }
public bool Register(string nick, string password, byte[] nickhashed, int counter, byte[] G, byte[] J, byte[] P, byte[] Q, byte[] Seed, byte[] X, byte[] Y) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); if (user == null) //si l'utilisateur n'existe deja pas { DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); DSAParameters key = Security.RecreateKey(counter, G, J, P, Q, Seed, X, Y); mycrypto.ImportParameters(key); ASCIIEncoding encoding = new ASCIIEncoding(); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verifie la cle publique recue { User newcommer = new User(nick, password, key); instance.AddUser(newcommer); instance.Serialiser(); result = true; } } return(result); }
public Message[] ReceiveAllMessage(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); Message[] message = null; User user = instance.SearchNick(nick); if (user != null) //on verifie si le demandeur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //on verifie la provenance de la demande { message = instance.Messages.ToArray<Message>(); } } return message; }
public bool SendPrivateMessage(string nick, string recipient, string message, byte[] messagehashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); //on verifie que l'auteur existe if (user != null) { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(message), messagehashed)) //on verifie la provenance du message { Message news = new Message(nick, message); User todeliver = instance.SearchNick(recipient); //on verifie la presence du destinataire if (todeliver != null) { Message privatemessage = new Message(nick, message); instance.RemoveUser(todeliver); todeliver.AddPrivateMessage(privatemessage); instance.AddUser(todeliver); instance.Serialiser(); result = true; } } } return result; }
public bool SendMessage(string nick, string message, byte[] messagehashed) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); //verification de l'utilisateur if (user != null) { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if(mycrypto.VerifyData(encoding.GetBytes(message), messagehashed)) //on verifie que le message provient bien de l'utilisateur { Message news = new Message(nick, message); instance.AddMessage(news); instance.Serialiser(); result = true; } } return result; }
public bool Register(string nick, string password,byte[] nickhashed, int counter, byte[] G, byte[] J, byte[] P, byte[] Q, byte[] Seed, byte[] X, byte[] Y) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); if (user == null) //si l'utilisateur n'existe deja pas { DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); DSAParameters key = Security.RecreateKey(counter, G, J, P, Q, Seed, X, Y); mycrypto.ImportParameters(key); ASCIIEncoding encoding = new ASCIIEncoding(); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verifie la cle publique recue { User newcommer = new User(nick, password, key); instance.AddUser(newcommer); instance.Serialiser(); result = true; } } return result; }
public Message[] ReceivePrivateMessage(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); Message[] privatemessage = null; if (user != null) //si l'utilisateur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verification de la provenance du message { privatemessage = user.PrivateMessage.ToArray<Message>(); } } return privatemessage; }
public Message[] ReceiveMessageNonRead(string nick, byte[] nickhashed) { Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); Message[] unread = null; if (user != null) //on verifie si l'utilisateur existe { ASCIIEncoding encoding = new ASCIIEncoding(); DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); mycrypto.ImportParameters(user.Publickey); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //on verifie la provenance de la demande { //requete LINQ pour recuperer les messages a lire unread = (from Message m in instance.Messages where m.Creation > user.LastRead select m).ToArray<Message>(); instance.RemoveUser(user); user.LastRead = DateTime.Now; //on modifie la date de derniere lecture instance.AddUser(user); instance.Serialiser(); } } return unread; }
public bool LogIn(string nick, string password,byte[] nickhashed, int counter, byte[] G, byte[] J, byte[] P, byte[] Q, byte[] Seed, byte[] X, byte[] Y) { bool result = false; Chat instance = new Chat(); instance.Deserialiser(); User user = instance.SearchNick(nick); if (user != null) //si l'utilisateur existe { if (user.CheckPassword(password)) //si le mot de passe de l'utilisateur est bon { DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider(); DSAParameters key = Security.RecreateKey(counter, G, J, P, Q, Seed, X, Y); mycrypto.ImportParameters(key); ASCIIEncoding encoding = new ASCIIEncoding(); if (mycrypto.VerifyData(encoding.GetBytes(nick), nickhashed)) //verification de la cle publique recue { result = true; instance.RemoveUser(user); user.Publickey = key; //on stocke la cle publique pour la reception prochaine de message instance.AddUser(user); instance.Serialiser(); } } } return result; }