private void AddNew() { Connection conn = new Connection(); string message = Language.Resource.Message; Security security = new Security(); bool check = conn.CheckExists(tbxName.Text); if (check) { MessageBox.Show(Language.Resource.NameExists, message); } else { conn.Name = tbxName.Text; conn.Server = tbxServer.Text; conn.Database = tbxDatabase.Text; conn.Username = tbxUser.Text; conn.Password = tbxPassword.Text; conn.Provider = tbxProvider.Text; int result = conn.Add(); if (result == 1) { frmManager manager = (frmManager)Application.OpenForms["frmManager"]; manager.SelectTab("tabConnections"); this.Close(); } } }
public int Add() { int result = 0; if (User.Current != null) { Security security = new Security(); bool check = CheckExists(Name); if (check) { result = -1; } else { XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); XmlNode node = connections.SelectSingleNode("/root/connections"); XmlNode connectionNode = connections.CreateElement("connection"); node.AppendChild(connectionNode); XmlNode nameNode = connections.CreateElement("name"); nameNode.AppendChild(connections.CreateTextNode(Name)); connectionNode.AppendChild(nameNode); XmlNode serverNode = connections.CreateElement("server"); serverNode.AppendChild(connections.CreateTextNode(Server)); connectionNode.AppendChild(serverNode); XmlNode dbNode = connections.CreateElement("dbname"); dbNode.AppendChild(connections.CreateTextNode(Database)); connectionNode.AppendChild(dbNode); XmlNode dbuserNode = connections.CreateElement("dbuser"); dbuserNode.AppendChild(connections.CreateTextNode(Username)); connectionNode.AppendChild(dbuserNode); XmlNode dbPassNode = connections.CreateElement("dbpass"); dbPassNode.AppendChild(connections.CreateTextNode(Password)); connectionNode.AppendChild(dbPassNode); XmlNode dbproviderNode = connections.CreateElement("provider"); dbproviderNode.AppendChild(connections.CreateTextNode(Provider)); connectionNode.AppendChild(dbproviderNode); security.SaveConnectionConfiguration(User.Current.Path, connections.InnerXml); result = 1; } } else { result = -2; } return result; }
public int Add() { int result = 0; if (User.Current != null) { Security security = new Security(); bool check = CheckExists(Name); if (check) { result = -2; } else { XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); XmlNode node = accounts.SelectSingleNode("/root/accounts"); XmlNode accountNode = accounts.CreateElement("account"); node.AppendChild(accountNode); XmlNode nameNode = accounts.CreateElement("name"); nameNode.AppendChild(accounts.CreateTextNode(Name)); accountNode.AppendChild(nameNode); XmlNode userNode = accounts.CreateElement("username"); userNode.AppendChild(accounts.CreateTextNode(Username)); accountNode.AppendChild(userNode); XmlNode passNode = accounts.CreateElement("password"); passNode.AppendChild(accounts.CreateTextNode(Password)); accountNode.AppendChild(passNode); XmlNode desNode = accounts.CreateElement("description"); desNode.AppendChild(accounts.CreateTextNode(Description)); accountNode.AppendChild(desNode); security.SaveAccountsConfiguration(User.Current.Path, accounts); result = 1; } } else { result = -1; } return result; }
public User GetBy(string name) { User user = new User(); if (Current != null) { Security security = new Security(); XmlDocument users = security.ReadUserConfiguration(User.Current.Path); XmlNode node = users.SelectSingleNode("/root/users/user[username='******']"); if (node != null) { user.UserName = node.SelectSingleNode("username").InnerText; user.Password = node.SelectSingleNode("password").InnerText; user.Email = node.SelectSingleNode("email").InnerText; user.PublicKey = node.SelectSingleNode("publickey").InnerText; user.PrivateKey = node.SelectSingleNode("privatekey").InnerText; } } else { user = null; } return user; }
public string GetAllJSON() { string result = ""; List<User> lstUser = new List<User>(); if (User.Current != null) { Security security = new Security(); XmlDocument users = security.ReadUserConfiguration(User.Current.Path); foreach (System.Xml.XmlNode node in users.SelectNodes("root/users/user")) { User user = new User(); user.UserName = node.SelectSingleNode("username").InnerText; user.Password = node.SelectSingleNode("password").InnerText; user.PublicKey = node.SelectSingleNode("publickey").InnerText; user.PrivateKey = node.SelectSingleNode("privatekey").InnerText; user.Email = node.SelectSingleNode("email").InnerText; lstUser.Add(user); } result = new JavaScriptSerializer().Serialize(lstUser); } return result; }
private void LoadUser() { User user = new User(); List<User> listUser = user.GetAll(); Security security = new Security(); lvUsers.Items.Clear(); foreach (User usr in listUser) { ListViewItem item = new ListViewItem(new[] { usr.UserName, usr.Email, security.encrypt(User.Current.PublicKey, usr.Password), usr.PublicKey, usr.PrivateKey }); lvUsers.Items.Add(item); } }
public string GetAllJSON() { string result = ""; List<Account> lstAccount = new List<Account>(); if (User.Current != null) { ThangDC.Core.Securities.Security security = new ThangDC.Core.Securities.Security(); System.Xml.XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); foreach (System.Xml.XmlNode node in accounts.SelectNodes("root/accounts/account")) { Account account = new Account(); account.Name = node.SelectSingleNode("name").InnerText; account.Username = node.SelectSingleNode("username").InnerText; account.Password = node.SelectSingleNode("password").InnerText; account.Description = node.SelectSingleNode("description").InnerText; lstAccount.Add(account); } result = new JavaScriptSerializer().Serialize(lstAccount); } return result; }
public List<MailServer> GetAll() { List<MailServer> listMailServer = new List<MailServer>(); if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); foreach (XmlNode node in mails.SelectNodes("root/mails/mail")) { MailServer mail = new MailServer(); mail.Name = node.SelectSingleNode("name").InnerText; mail.Server = node.SelectSingleNode("server").InnerText; mail.Port = int.Parse(node.SelectSingleNode("port").InnerText); mail.Username = node.SelectSingleNode("user").InnerText; mail.Password = node.SelectSingleNode("password").InnerText; listMailServer.Add(mail); } } return listMailServer; }
public bool CheckExists(string name) { bool result = false; if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); foreach (XmlNode node in mails.SelectNodes("root/mails/mail")) { string _name = node.SelectSingleNode("name").InnerText; if (name == _name) { result = true; break; } else { result = false; } } } return result; }
public int Register() { int result = 0; if (string.IsNullOrEmpty(UserName)) { result = -1; } else if (string.IsNullOrEmpty(Email)) { result = -2; } else if (string.IsNullOrEmpty(Password)) { result = -3; } else if (string.IsNullOrEmpty(Confirm)) { result = -4; } else { string MatchEmailPattern = @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\." + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$"; bool checkEmail = System.Text.RegularExpressions.Regex.IsMatch(Email, MatchEmailPattern); if (!checkEmail) { result = -5; } else { if (Password != Confirm) { result = -6; } else { string publicKey = ""; string privateKey = ""; CspParameters cspParams = null; RSACryptoServiceProvider rsaProvider = null; cspParams = new CspParameters(); cspParams.ProviderType = 1; cspParams.Flags = CspProviderFlags.UseArchivableKey; cspParams.KeyNumber = (int)KeyNumber.Exchange; rsaProvider = new RSACryptoServiceProvider(cspParams); publicKey = rsaProvider.ToXmlString(false); privateKey = rsaProvider.ToXmlString(true); User us = new User(); us.UserName = UserName; us.Email = Email; us.PrivateKey = privateKey; us.PublicKey = publicKey; us.Path = Path; byte[] salt = new byte[16]; byte[] hashPassword = new byte[16]; Security security = new Security(); security.HashPassword(Password, out salt, out hashPassword); string s = Convert.ToBase64String(salt); string p = Convert.ToBase64String(hashPassword); us.Password = p; us.Salt = s; if (!System.IO.File.Exists(Path)) { security.SaveConnectionConfiguration(Path, "test", "test", "test", "test", "test", "test"); security.SaveMailConfiguration(Path, "test", "test", 0, "test", "test"); security.SaveAccountsConfiguration(Path, "test", "test", "test", "test"); security.SaveUserConfiguration(Path, UserName, Email, p, privateKey, publicKey, s); Login(); result = 1; } else { XmlDocument users = security.ReadUserConfiguration(Path); bool check = CheckUserAndEmailExists(UserName, Email, users); if (!check) { XmlNode node = users.SelectSingleNode("/root/users"); XmlNode userNode = users.CreateElement("user"); node.AppendChild(userNode); XmlNode usernameNode = users.CreateElement("username"); usernameNode.AppendChild(users.CreateTextNode(UserName)); userNode.AppendChild(usernameNode); XmlNode emailNode = users.CreateElement("email"); emailNode.AppendChild(users.CreateTextNode(Email)); userNode.AppendChild(emailNode); XmlNode passNode = users.CreateElement("password"); passNode.AppendChild(users.CreateTextNode(p)); userNode.AppendChild(passNode); XmlNode publickeyNode = users.CreateElement("publickey"); publickeyNode.AppendChild(users.CreateCDataSection(PublicKey)); userNode.AppendChild(publickeyNode); XmlNode privateNode = users.CreateElement("privatekey"); privateNode.AppendChild(users.CreateCDataSection(PrivateKey)); userNode.AppendChild(privateNode); XmlNode saltNode = users.CreateElement("salt"); saltNode.AppendChild(users.CreateCDataSection(s)); userNode.AppendChild(saltNode); security.SaveUserConfiguration(Path, users.InnerXml); Login(); result = 1; } else { result = -7; } } } } } return result; }
public Connection GetBy(string name) { Connection conn = new Connection(); if (User.Current != null) { Security security = new Security(); XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + name + "']"); if (node != null) { conn.Name = node.SelectSingleNode("name").InnerText; conn.Server = node.SelectSingleNode("server").InnerText; conn.Database = node.SelectSingleNode("dbname").InnerText; conn.Username = node.SelectSingleNode("dbuser").InnerText; conn.Password = node.SelectSingleNode("dbpass").InnerText; conn.Provider = node.SelectSingleNode("provider").InnerText; } else { conn = null; } } else { conn = null; } return conn; }
public string GetAllJSON() { string result = ""; List<Connection> listConnection = new List<Connection>(); if (User.Current != null) { Security security = new Security(); XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); foreach (XmlNode node in connections.SelectNodes("root/connections/connection")) { Connection conn = new Connection(); conn.Name = node.SelectSingleNode("name").InnerText; conn.Server = node.SelectSingleNode("server").InnerText; conn.Database = node.SelectSingleNode("dbname").InnerText; conn.Username = node.SelectSingleNode("dbuser").InnerText; conn.Password = node.SelectSingleNode("dbpass").InnerText; conn.Provider = node.SelectSingleNode("provider").InnerText; listConnection.Add(conn); } result = new JavaScriptSerializer().Serialize(listConnection); } return result; }
public List<Connection> GetAll() { List<Connection> listConnection = new List<Connection>(); if (User.Current != null) { Security security = new Security(); XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); foreach (XmlNode node in connections.SelectNodes("root/connections/connection")) { Connection conn = new Connection(); conn.Name = node.SelectSingleNode("name").InnerText; conn.Server = node.SelectSingleNode("server").InnerText; conn.Database = node.SelectSingleNode("dbname").InnerText; conn.Username = node.SelectSingleNode("dbuser").InnerText; conn.Password = node.SelectSingleNode("dbpass").InnerText; conn.Provider = node.SelectSingleNode("provider").InnerText; listConnection.Add(conn); } } return listConnection; }
public int Update() { int result = 0; if (User.Current != null) { Security security = new Security(); XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); XmlNode node = accounts.SelectSingleNode("/root/accounts/account[name='" + Name + "']"); if (node != null) { node.SelectSingleNode("username").InnerText = Username; node.SelectSingleNode("password").InnerText = Password; node.SelectSingleNode("description").InnerText = Description; //node.SelectSingleNode("name").InnerText = Name; security.SaveAccountsConfiguration(User.Current.Path, accounts); result = 1; } else { result = -2; } } else { result = -1; } return result; }
public string GetByJSON(string name) { string result = ""; Account account = new Account(); if (User.Current != null) { Security security = new Security(); XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); XmlNode node = accounts.SelectSingleNode("/root/accounts/account[name='" + name + "']"); if (node != null) { account.Name = node.SelectSingleNode("name").InnerText; account.Username = node.SelectSingleNode("username").InnerText; account.Password = node.SelectSingleNode("password").InnerText; account.Description = node.SelectSingleNode("description").InnerText; result = new JavaScriptSerializer().Serialize(account); } } return result; }
public Account GetBy(string name) { Account account = new Account(); if (User.Current != null) { Security security = new Security(); XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); XmlNode node = accounts.SelectSingleNode("/root/accounts/account[name='" + name + "']"); if (node != null) { account.Name = node.SelectSingleNode("name").InnerText; account.Username = node.SelectSingleNode("username").InnerText; account.Password = node.SelectSingleNode("password").InnerText; account.Description = node.SelectSingleNode("description").InnerText; } } return account; }
public string GetByJSON(string name) { string result = ""; User user = new User(); if (Current != null) { Security security = new Security(); XmlDocument users = security.ReadUserConfiguration(User.Current.Path); XmlNode node = users.SelectSingleNode("/root/users/user[username='******']"); if (node != null) { user.UserName = node.SelectSingleNode("username").InnerText; user.Password = node.SelectSingleNode("password").InnerText; user.Email = node.SelectSingleNode("email").InnerText; user.PublicKey = node.SelectSingleNode("publickey").InnerText; user.PrivateKey = node.SelectSingleNode("privatekey").InnerText; } result = new JavaScriptSerializer().Serialize(user); } return result; }
public string GetByJSON(string name) { string result = ""; Connection conn = new Connection(); if (User.Current != null) { Security security = new Security(); XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + name + "']"); if (node != null) { conn.Name = node.SelectSingleNode("name").InnerText; conn.Server = node.SelectSingleNode("server").InnerText; conn.Database = node.SelectSingleNode("dbname").InnerText; conn.Username = node.SelectSingleNode("dbuser").InnerText; conn.Password = node.SelectSingleNode("dbpass").InnerText; conn.Provider = node.SelectSingleNode("provider").InnerText; result = new JavaScriptSerializer().Serialize(conn); } } return result; }
public int Login() { int result = 0; if (string.IsNullOrEmpty(UserName)) { result = -2; } else if (string.IsNullOrEmpty(Password)) { result = -3; } else { if (System.IO.File.Exists(Path)) { Security security = new Security(); XmlDocument doc = security.ReadUserConfiguration(Path); string _username = ""; string _password = ""; string _email = ""; string _publickey = ""; string _privatekey = ""; string _path = ""; string _salt = ""; foreach (XmlNode node in doc.SelectNodes("root/users/user")) { if (node.SelectSingleNode("username") != null && node.SelectSingleNode("password") != null) { _username = node.SelectSingleNode("username").InnerText; _password = node.SelectSingleNode("password").InnerText; _salt = node.SelectSingleNode("salt").InnerText; if (UserName == _username && security.CheckPassword(Password, Convert.FromBase64String(_salt), Convert.FromBase64String(_password))) { User us = new User(); _email = node.SelectSingleNode("email").InnerText; _publickey = node.SelectSingleNode("publickey").InnerText; _privatekey = node.SelectSingleNode("privatekey").InnerText; _path = Path; us.UserName = _username; us.Email = _email; us.PublicKey = _publickey; us.PrivateKey = _privatekey; us.Path = _path; _username = null; _password = null; _email = null; _publickey = null; _privatekey = null; UserName = null; Password = null; User.Current = us; result = 1; break; } else { result = -4; } } } } else { result = -3; } } return result; }
public int Update() { int result = 0; if (User.Current != null) { bool check = CheckExists(Name); if (!check) { result = -1; } else { Security security = new Security(); XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path); XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + Name + "']"); if (node != null) { node.SelectSingleNode("name").InnerText = Name; node.SelectSingleNode("server").InnerText = Server; node.SelectSingleNode("dbname").InnerText = Database; node.SelectSingleNode("dbuser").InnerText = Username; node.SelectSingleNode("dbpass").InnerText = Password; node.SelectSingleNode("provider").InnerText = Provider; security.SaveConnection(User.Current.Path, connections); result = 1; } else { result = -3; } } } else { result = -2; } return result; }
public int Update() { int result = 0; if (User.Current != null) { Security security = new Security(); XmlDocument users = security.ReadUserConfiguration(User.Current.Path); XmlNode node = users.SelectSingleNode("/root/users/user[username='******']"); if (node != null) { node.SelectSingleNode("username").InnerText = UserName; node.SelectSingleNode("password").InnerText = Password; node.SelectSingleNode("email").InnerText = Email; security.SaveUserConfiguration(User.Current.Path, users.OuterXml); result = 1; } } return result; }
public MailServer GetBy(string name) { MailServer mailServer = new MailServer(); if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']"); if (node != null) { mailServer.Name = node.SelectSingleNode("name").InnerText; mailServer.Server = node.SelectSingleNode("server").InnerText; mailServer.Username = node.SelectSingleNode("user").InnerText; mailServer.Password = node.SelectSingleNode("password").InnerText; int port = 0; int.TryParse(node.SelectSingleNode("port").InnerText, out port); mailServer.Port = port; } else { mailServer = null; } } else { mailServer = null; } return mailServer; }
public bool Delete() { bool result = false; if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + Name + "']"); if (node != null) { node.ParentNode.RemoveChild(node); security.SaveMailConfiguration(User.Current.Path, mails.InnerXml); result = true; } } return result; }
public int Update() { int result = 0; if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + Name + "']"); if (node != null) { node.SelectSingleNode("name").InnerText = Name; node.SelectSingleNode("server").InnerText = Server; node.SelectSingleNode("user").InnerText = Username; node.SelectSingleNode("password").InnerText = Password; node.SelectSingleNode("port").InnerText = Port.ToString(); security.SaveMailConfiguration(User.Current.Path, mails.InnerXml); result = 1; } } else { result = -1; } return result; }
public string GetAllJSON() { string result = ""; List<MailServer> listMailServer = new List<MailServer>(); if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); foreach (XmlNode node in mails.SelectNodes("root/mails/mail")) { MailServer mail = new MailServer(); mail.Name = node.SelectSingleNode("name").InnerText; mail.Server = node.SelectSingleNode("server").InnerText; mail.Port = int.Parse(node.SelectSingleNode("port").InnerText); mail.Username = node.SelectSingleNode("user").InnerText; mail.Password = node.SelectSingleNode("password").InnerText; listMailServer.Add(mail); } result = new JavaScriptSerializer().Serialize(listMailServer); } return result; }
public bool Delete() { bool result = false; if (User.Current != null) { ThangDC.Core.Securities.Security security = new ThangDC.Core.Securities.Security(); System.Xml.XmlDocument accounts = security.ReadAccountConfiguration(User.Current.Path); System.Xml.XmlNode node = accounts.SelectSingleNode("/root/accounts/account[name='" + Name + "']"); if (node != null) { node.ParentNode.RemoveChild(node); security.SaveAccountsConfiguration(User.Current.Path, accounts); result = true; } } return result; }
public string GetByJSON(string name) { string result = ""; MailServer mailServer = new MailServer(); if (User.Current != null) { Security security = new Security(); XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']"); if (node != null) { mailServer.Name = node.SelectSingleNode("name").InnerText; mailServer.Server = node.SelectSingleNode("server").InnerText; mailServer.Username = node.SelectSingleNode("user").InnerText; mailServer.Password = node.SelectSingleNode("password").InnerText; int port = 0; int.TryParse(node.SelectSingleNode("port").InnerText, out port); mailServer.Port = port; result = new JavaScriptSerializer().Serialize(mailServer); } } return result; }
public List<User> GetAll() { List<User> lstUser = new List<User>(); if (User.Current != null) { Security security = new Security(); XmlDocument users = security.ReadUserConfiguration(User.Current.Path); foreach (System.Xml.XmlNode node in users.SelectNodes("root/users/user")) { User user = new User(); user.UserName = node.SelectSingleNode("username").InnerText; user.Password = node.SelectSingleNode("password").InnerText; user.PublicKey = node.SelectSingleNode("publickey").InnerText; user.PrivateKey = node.SelectSingleNode("privatekey").InnerText; user.Email = node.SelectSingleNode("email").InnerText; lstUser.Add(user); } } return lstUser; }
public int Add() { int result = 0; if (User.Current != null) { Security security = new Security(); bool check = CheckExists(Name); if (check) { result = -2; } else { int Num; bool isNum = int.TryParse(Port.ToString(), out Num); if (isNum) { XmlDocument mails = security.ReadMailConfiguration(User.Current.Path); XmlNode node = mails.SelectSingleNode("/root/mails"); XmlNode mailNode = mails.CreateElement("mail"); node.AppendChild(mailNode); XmlNode nameNode = mails.CreateElement("name"); nameNode.AppendChild(mails.CreateTextNode(Name)); mailNode.AppendChild(nameNode); XmlNode serverNode = mails.CreateElement("server"); serverNode.AppendChild(mails.CreateTextNode(Server)); mailNode.AppendChild(serverNode); XmlNode userNode = mails.CreateElement("user"); userNode.AppendChild(mails.CreateTextNode(Username)); mailNode.AppendChild(userNode); XmlNode passNode = mails.CreateElement("password"); passNode.AppendChild(mails.CreateTextNode(Password)); mailNode.AppendChild(passNode); XmlNode portNode = mails.CreateElement("port"); portNode.AppendChild(mails.CreateTextNode(Port.ToString())); mailNode.AppendChild(portNode); security.SaveMailConfiguration(User.Current.Path, mails.InnerXml); result = 1; } else { result = -3; } } } else { result = -1; } return result; }
private void LoadMail() { MailServer mailserver = new MailServer(); List<MailServer> lstMail = mailserver.GetAll(); Security security = new Security(); lvMails.Items.Clear(); foreach(MailServer m in lstMail) { ListViewItem item = new ListViewItem(new[] { m.Name, m.Server, m.Username, security.encrypt(User.Current.PublicKey, m.Password), m.Port.ToString() }); lvMails.Items.Add(item); } }