Beispiel #1
0
        /// <summary>
        /// Call this from your login form
        /// </summary>
        /// <param name="email">Player's email</param>
        /// <param name="password">Player's password</param>
        /// <returns>True when the login succeeds</returns>
        public bool Login(string email, string password)
        {
            var player = EmailAuthUtils.FindPlayer(email);

            if (player == null)
            {
                return(false);
            }

            if (!Hash.Check(password, player.password))
            {
                return(false);
            }

            Auth.Login(player);

            PlayerHasLoggedIn(player);

            return(true);
        }
        /// <summary>
        /// Call this from your registration form
        /// </summary>
        /// <param name="email">Player's email</param>
        /// <param name="password">Player's password</param>
        public EmailRegisterResponse Register(string email, string password)
        {
            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            string normalizedEmail = EmailAuthUtils.NormalizeEmail(email);

            if (!EmailAuthUtils.IsEmailValid(normalizedEmail))
            {
                return(EmailRegisterResponse.InvalidEmail);
            }

            if (!IsPasswordStrong(password))
            {
                return(EmailRegisterResponse.WeakPassword);
            }

            if (EmailAuthUtils.FindPlayer(email) != null)
            {
                return(EmailRegisterResponse.EmailTaken);
            }

            var player = CreateNewPlayer(normalizedEmail, password);

            player.Save();

            Auth.Login(player);

            PlayerHasRegistered(player);

            return(EmailRegisterResponse.Ok);
        }