Exemplo n.º 1
0
        private void CreateLogin(string path, string username, string password)
        {
            username.ValidateUsername();
            password.ValidatePassword();

            var hashedPassword = SecureCrypto.Hash64(password, username);

            File.WriteAllText(path + "/" + username + ".lgn", hashedPassword);
        }
        static public AuthToken FromToken(this EncryptionCertificateService ecs, string token)
        {
            string authToken = SecureCrypto.DecryptToken(ecs.GetCertificate(), token); //Crypto.Decrypt(token, Globals.MasterPassword);

            var at = authToken.Split('|');

            return(new AuthToken()
            {
                Username = at[1],
                AuthType = (AuthTypes)int.Parse(at[2]),
                Expire = long.Parse(at[3])
            });
        }
Exemplo n.º 3
0
        private AuthToken CreateAuthToken(string path, string username, string password, AuthToken.AuthTypes authType, int expireMiniutes = 30)
        {
            var fi = new FileInfo(path + "/" + username + ".lgn");

            if (fi.Exists)
            {
                if (SecureCrypto.VerifyPassword(password, File.ReadAllText(fi.FullName), username))
                {
                    return(new AuthToken(username, authType, new DateTimeOffset(DateTime.UtcNow.Ticks, new TimeSpan(0, 30, 0))));
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        public void ChangeTokenUserPassword(string username, string newPassword)
        {
            newPassword.ValidatePassword();

            var di = new DirectoryInfo(_mapServerService.Options.LoginManagerRootPath + "/token");
            var fi = new FileInfo(di.FullName + "/" + username + ".lgn");

            if (!fi.Exists)
            {
                throw new MapServerException("User '" + username + "' do not exists");
            }

            var hashedPassword = SecureCrypto.Hash64(newPassword, username);

            File.WriteAllText(fi.FullName, hashedPassword);
        }
 static public string ToToken(this EncryptionCertificateService ecs, AuthToken authToken)
 {
     return(SecureCrypto.EncryptToken(
                ecs.GetCertificate(),
                Guid.NewGuid().ToString("N") + "|" + authToken.Username + "|" + (int)authToken.AuthType + "|" + authToken.Expire.ToString(), resultType: SecureCrypto.ResultType.Base62));
 }