Ejemplo n.º 1
0
        /// <summary>
        /// Đặt mật khẩu mới
        /// </summary>
        /// <param name="idPerson"></param>
        /// <param name="passWord"></param>
        /// <param name="accountType"></param>
        public static void SetNewPassword(string idPerson, string passWord, AccountType accountType)
        {
            string path = GetDataPath() + "UserData\\";

            switch (accountType)
            {
            case AccountType.ADMIN:
                path += "AdminUserData.xml";
                break;

            case AccountType.LIBRARIAN:
                path += "LibrarianUserData.xml";
                break;

            default:
                path += "MemberUserData.xml";
                break;
            }

            try
            {
                XDocument DataXML    = XDocument.Load(path);
                XElement  updateUser = DataXML.Descendants("User").Where(c => c.Attribute("PersonID").Value.Equals(idPerson)).FirstOrDefault();

                updateUser.Element("Password").Value = PassWordEncode.MD5Hash(PassWordEncode.Base64Encode(passWord));

                DataXML.Save(path);
            }
            catch (Exception) { }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Kiểm tra mật khẩu
        /// </summary>
        /// <param name="idPerson"></param>
        /// <param name="passWord"></param>
        /// <param name="accountType"></param>
        /// <returns></returns>
        public static bool CheckPassword(string idPerson, string passWord, AccountType accountType)
        {
            string path = GetDataPath() + "UserData\\";

            switch (accountType)
            {
            case AccountType.ADMIN:
                path += "AdminUserData.xml";
                break;

            case AccountType.LIBRARIAN:
                path += "LibrarianUserData.xml";
                break;

            default:
                path += "MemberUserData.xml";
                break;
            }

            try
            {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(path);
                DataTable dt = new DataTable();
                dt = dataSet.Tables["User"];

                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["PersonID"].ToString() == idPerson && dr["Password"].ToString() == PassWordEncode.MD5Hash(PassWordEncode.Base64Encode(passWord)))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception) { }

            return(false);
        }