Пример #1
0
        public static string Login(string username, string password)
        {
            ZooTykoonDb db = new ZooTykoonDb();

            foreach (User user in db.Users.ToList())
            {
                if (username == user.Name && HashSHA256(password) == user.Password)
                {
                    Random rnd = new Random();
                    user.SessionToken = HashSHA256(rnd.Next().ToString());
                    db.SaveChanges();
                    return user.SessionToken;
                }
            }

            return null;
        }
Пример #2
0
        public static void Logout(string sessionToken)
        {
            ZooTykoonDb db = new ZooTykoonDb();

            foreach (User user in db.Users.ToList())
            {
                if (sessionToken == user.SessionToken)
                {
                    user.SessionToken = null;
                    db.SaveChanges();
                    return;
                }
            }

            return;
        }