Exemplo n.º 1
0
        public static User RegUser(this IDbSet<User> obj, string name, string pass)
        {
            if (obj.HasUser(name)) return null; //TODO maybe throw an Exception

            Hash hash = new Hash(pass);

            User user = new User()
            {
                Name = name,
                PasswordHash = hash.HashStringValue,
                Salt = hash.Salt
            };
            return obj.Add(user);
        }
Exemplo n.º 2
0
        public static User Auth(this IDbSet<User> obj, string name, string pass)
        {
            User user = obj.FirstOrDefault(u => u.Name == name);
            if (user == null) return null;

            Hash hash = new Hash(pass, user.Salt);

            if (hash.HashStringValue == user.PasswordHash)
            {
                return user;
            }

            return null;
            //TODO Maybe should throw an exception...
        }