示例#1
0
        public UserInfo GetUser(string userName)
        {
            using (var query = Session.CreateQuery()) {
                var table            = query.Access().GetTable(PasswordTableName);
                var unameColumn      = table.GetResolvedColumnName(0);
                var methodColumn     = table.GetResolvedColumnName(1);
                var methodArgsColumn = table.GetResolvedColumnName(2);
                var tokenColumn      = table.GetResolvedColumnName(3);

                var t = table.SimpleSelect(query, unameColumn, SqlExpressionType.Equal, SqlExpression.Constant(userName));
                if (t.RowCount == 0)
                {
                    throw new SecurityException(String.Format("User '{0}' is not registered.", userName));
                }

                var method     = t.GetValue(0, methodColumn);
                var methodArgs = t.GetValue(0, methodArgsColumn);
                var argBytes   = ((SqlBinary)methodArgs.Value).ToByteArray();
                var args       = DeserializeArguments(argBytes);
                var token      = t.GetValue(0, tokenColumn);

                var identification = new UserIdentification(method, token);
                foreach (var arg in args)
                {
                    identification.Arguments[arg.Key] = arg.Value;
                }

                return(new UserInfo(userName, identification));
            }
        }
示例#2
0
 public UserIdentification CreateIdentification(string input)
 {
     var salt = HashFunctions.HmacSha512.GenerateSaltString();
     var token = HashFunctions.HmacSha512.MakePbkdf2String(input, salt, 512);
     var id = new UserIdentification(KnownUserIdentifications.Pkcs12, token);
     id.Arguments.Add("salt", salt);
     return id;
 }
        private static void CreatePublicUser(IQuery query)
        {
            var userName = User.PublicName;
            var userId = new UserIdentification(KnownUserIdentifications.ClearText, "###");
            var userInfo = new UserInfo(userName, userId);

            query.Access().CreateUser(userInfo);
        }
示例#4
0
        private static void CreatePublicUser(IQuery query)
        {
            var userName = User.PublicName;
            var userId   = new UserIdentification(KnownUserIdentifications.ClearText, "###");
            var userInfo = new UserInfo(userName, userId);

            query.Access().CreateUser(userInfo);
        }
示例#5
0
        public static UserIdentification Pkcs12(string salt)
        {
            var id = new UserIdentification("hash");

            id.Arguments["salt"]      = salt;
            id.Arguments["mechanism"] = "pkcs12";
            return(id);
        }
        public UserIdentification CreateIdentification(string input)
        {
            var salt  = HashFunctions.HmacSha512.GenerateSaltString();
            var token = HashFunctions.HmacSha512.MakePbkdf2String(input, salt, 512);
            var id    = new UserIdentification(KnownUserIdentifications.Pkcs12, token);

            id.Arguments.Add("salt", salt);
            return(id);
        }
示例#7
0
        public UserInfo(string name, UserIdentification identification)
        {
            if (String.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            if (identification == null)
                throw new ArgumentNullException("identification");

            Name = name;
            Identification = identification;
        }
示例#8
0
        public bool VerifyIdentification(string input, UserIdentification identification)
        {
            string salt;
            object arg;
            if (!identification.Arguments.TryGetValue("salt", out arg)) {
                salt = HashFunctions.HmacSha512.GenerateSaltString();
            } else {
                salt = arg.ToString();
            }

            return HashFunctions.HmacSha512.VerifyPbkdf2String(identification.Token, input, salt);
        }
示例#9
0
        public UserInfo(string name, UserIdentification identification)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (identification == null)
            {
                throw new ArgumentNullException("identification");
            }

            Name           = name;
            Identification = identification;
        }
        public bool VerifyIdentification(string input, UserIdentification identification)
        {
            string salt;
            object arg;

            if (!identification.Arguments.TryGetValue("salt", out arg))
            {
                salt = HashFunctions.HmacSha512.GenerateSaltString();
            }
            else
            {
                salt = arg.ToString();
            }

            return(HashFunctions.HmacSha512.VerifyPbkdf2String(identification.Token, input, salt));
        }
示例#11
0
        public UserInfo GetUser(string userName)
        {
            var table = QueryContext.GetTable(SystemSchema.PasswordTableName);
            var unameColumn = table.GetResolvedColumnName(0);
            var methodColumn = table.GetResolvedColumnName(1);
            var methodArgsColumn = table.GetResolvedColumnName(2);

            var t = table.SimpleSelect(QueryContext, unameColumn, SqlExpressionType.Equal, SqlExpression.Constant(userName));
            if (t.RowCount == 0)
                throw new SecurityException(String.Format("User '{0}' is not registered.", userName));

            var method = t.GetValue(0, methodColumn);
            var methodArgs = t.GetValue(0, methodArgsColumn);
            var argBytes = ((SqlBinary) methodArgs.Value).ToByteArray();
            var args = DeserializeArguments(argBytes);

            var identification = new UserIdentification(method);
            foreach (var arg in args) {
                identification.Arguments[arg.Key] = arg.Value;
            }

            return new UserInfo(userName, identification);
        }
示例#12
0
 public bool VerifyIdentification(string input, UserIdentification identification)
 {
     return String.Equals(input, identification.Token);
 }
示例#13
0
 public bool VerifyIdentification(string input, UserIdentification identification)
 {
     return(String.Equals(input, identification.Token));
 }
示例#14
0
 static UserIdentification()
 {
     PlainText = new UserIdentification("plain");
 }