示例#1
0
        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;
        }