Beispiel #1
0
        public void Check()
        {
            var secure = PBKDF2.Encrypt("echoes");
            var crpt   = new PBKDF2();

            Assert.Throws <NotImplementedException>(() => crpt.Decrypt(secure));
        }
Beispiel #2
0
        /// <summary>
        /// 默认站点配置
        /// </summary>
        /// <returns></returns>
        public static TinyConfiguration LoadDefaultConfiguration()
        {
            TinyConfiguration _tinyConfiguration = new TinyConfiguration();

            _tinyConfiguration = new TinyConfiguration();
            _tinyConfiguration.AuthExpireSeconds = 28800;
            _tinyConfiguration.IsSitePublic      = true;
            _tinyConfiguration.NavigationLinks   = new string[][]
            {
                new string[] { "/", "HOME" },
                new string[] { "https://estermont.wordpress.com/", "DOWNLOAD" },
                new string[] { "https://github.com/yahch", "GITHUB" }
            };
            _tinyConfiguration.PageSize                  = 5;
            _tinyConfiguration.Password                  = PBKDF2.Encrypt("admin");
            _tinyConfiguration.Port                      = 6600;
            _tinyConfiguration.SiteBuildDate             = new DateTime(2018, 3, 15);
            _tinyConfiguration.SiteName                  = "TiNY";
            _tinyConfiguration.Username                  = "******";
            _tinyConfiguration.Encryption                = false;
            _tinyConfiguration.LoginRetryTimeSpanSeconds = 30;
            _tinyConfiguration.DataDirectory             = Root;

            return(_tinyConfiguration);
        }
Beispiel #3
0
        public void Expect_Equal()
        {
            var secure = PBKDF2.Encrypt("echoes");

            Assert.AreEqual("PBKDF2", secure.Algorithm);
            Assert.AreEqual("64000", secure.Parameters);
        }
Beispiel #4
0
        public void Expect_Not_Equal()
        {
            var hash1 = PBKDF2.Encrypt("echoes");
            var hash2 = PBKDF2.Encrypt("echoes");

            Assert.AreNotEqual(hash1.Salt, hash2.Salt);
            Assert.AreNotEqual(hash1.Hash, hash2.Hash);
        }
        public static string Encrypt(string text, string key1, string key2)
        {
            string outPut = text;

            outPut = XOR.EncryptDecrypt(outPut, 182524);
            outPut = PBKDF2.Encrypt(outPut, key1);
            outPut = XOR.EncryptDecrypt(outPut, 498356);
            outPut = AES.Encrypt(outPut, key2);
            outPut = XOR.EncryptDecrypt(outPut, 606258);
            return(outPut);
        }
Beispiel #6
0
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static Guid?ValidateUser(string username, string password)
        {
            var config = TinyfxCore.Configuration;

            if (username == config.Username && PBKDF2.Encrypt(password) == config.Password)
            {
                return(_guid);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        public string RenderChangePassword(string method, string username, string password, string repassword)
        {
            string changePasswordTmpl = ResourceHelper.LoadStringResource("changepassword.html");
            string adminHtmlTmpl      = ResourceHelper.LoadStringResource("admin.html");

            if (method == "GET")
            {
                return(adminHtmlTmpl.AsHtmlFromTemplate(new
                {
                    RenderBody = changePasswordTmpl.AsHtmlFromTemplate(new
                    {
                        Configuration = _tinyConfiguration
                    }),
                    Configuration = _tinyConfiguration
                }));
            }

            Regex regUsername = new Regex(@"^[a-zA-Z][a-zA-Z0-9_]{4,15}$");
            Regex regPassword = new Regex(@"^[a-zA-Z]\w{5,17}$");
            bool  valid       = true;

            string error = null, success = null;

            if (!regUsername.IsMatch(username))
            {
                error = "请输入正确的用户名";
                valid = false;
            }

            if (!regPassword.IsMatch(password))
            {
                error = "请输入有效的密码";
                valid = false;
            }

            if (repassword != password)
            {
                error = "两次密码不一致";
                valid = false;
            }

            if (valid)
            {
                _tinyConfiguration.Username = username;
                _tinyConfiguration.Password = PBKDF2.Encrypt(password);
                if (TinyfxCore.UpdateConfig(_tinyConfiguration))
                {
                    success = "修改密码成功,下次登录生效。";
                }
                else
                {
                    error = "修改密码失败";
                }
            }

            return(adminHtmlTmpl.AsHtmlFromTemplate(new
            {
                RenderBody = changePasswordTmpl.AsHtmlFromTemplate(new
                {
                    Configuration = _tinyConfiguration,
                    Error = error,
                    Success = success
                }),
                Configuration = _tinyConfiguration
            }));
        }
Beispiel #8
0
        public void Check()
        {
            var secure = PBKDF2.Encrypt("echoes");

            Assert.True(secure.Cryptography().Same(secure, "echoes"));
        }