Esempio n. 1
0
        public UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random)
        {
            string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phoneNumber);

            User existingUser = UserDbQuery.Instance.GetUserFromPhone(normalizedPhone);

            if (existingUser == null)
            {
                throw new Exception("User not registered");
            }

            Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.UserData.Secret, 30, 6);
            if (!oneTimePasswordValidator.Verify(oneTimePassword))
            {
                throw new Exception("Invalid one-time password");
            }

            UserCookie cookie = UserCookie.GetCookie(existingUser.UserData, deviceId);

            if (cookie == null)
            {
                cookie = UserCookie.CreateCookie(existingUser.UserData, deviceId);
            }
            else
            {
                cookie.Update();
            }

            return(cookie);
        }
Esempio n. 2
0
        public UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random)
        {
            string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phoneNumber);

            User existingUser = UserDbQuery.Instance.GetUserFromPhone(normalizedPhone);
            if (existingUser == null)
            {
                throw new Exception("User not registered");
            }

            Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.UserData.Secret, 30, 6);
            if (!oneTimePasswordValidator.Verify(oneTimePassword))
            {
                throw new Exception("Invalid one-time password");
            }

            UserCookie cookie = UserCookie.GetCookie(existingUser.UserData, deviceId);
            if (cookie == null)
            {
                cookie = UserCookie.CreateCookie(existingUser.UserData, deviceId);
            }
            else
            {
                cookie.Update();
            }

            return cookie;
        }
Esempio n. 3
0
        private void SendSmsWithConfirmationCode(DAL.User user)
        {
//            Task.Factory.StartNew(() =>
            {
                Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(user.Secret, 30, 6);

                int code = oneTimePasswordValidator.Now();

                Authenticator.SmsSender sender = new Authenticator.SmsSender();

                sender.SendSMS(user.PhoneNumber, code);
            }//);
        }
Esempio n. 4
0
        /// <summary>
        /// Validates the one-time password for the user
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="cookie"></param>
        /// <returns></returns>
        public DAL.UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random)
        {
            string normalizedPhone = DAL.PhoneNumberUtils.ValidatePhoneNumber(phoneNumber);

            DAL.User existingUser = DAL.UserService.Instance.GetUserFromPhone(normalizedPhone);
            if (existingUser == null)
            {
                throw new Exception("User not registered");
            }

            Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.Secret, 30, 6);
            if (!oneTimePasswordValidator.Verify(oneTimePassword))
            {
                throw new Exception("Invalid one-time password");
            }

            DAL.UserService.Instance.UpdateDeviceId(existingUser, deviceId);

            DAL.UserCookie cookie = new DAL.UserCookie(existingUser, deviceId);

            return(cookie);
        }
Esempio n. 5
0
        private void SendSmsWithConfirmationCode(DAL.User user)
        {
            //            Task.Factory.StartNew(() =>
            {
                Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(user.Secret, 30, 6);

                int code = oneTimePasswordValidator.Now();

                Authenticator.SmsSender sender = new Authenticator.SmsSender();

                sender.SendSMS(user.PhoneNumber, code);
            }//);
        }
Esempio n. 6
0
        /// <summary>
        /// Validates the one-time password for the user
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="cookie"></param>
        /// <returns></returns>
        public DAL.UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random)
        {
            string normalizedPhone = DAL.PhoneNumberUtils.ValidatePhoneNumber(phoneNumber);

            DAL.User existingUser = DAL.UserService.Instance.GetUserFromPhone(normalizedPhone);
            if (existingUser == null)
            {
                throw new Exception("User not registered");
            }

            Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.Secret, 30, 6);
            if (!oneTimePasswordValidator.Verify(oneTimePassword))
            {
                throw new Exception("Invalid one-time password");
            }

            DAL.UserService.Instance.UpdateDeviceId(existingUser, deviceId);

            DAL.UserCookie cookie = new DAL.UserCookie(existingUser, deviceId);

            return cookie;
        }