Пример #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);
        }
Пример #2
0
        public static bool Validate(UserData user, UserCookie cookie)
        {
            UserCookie realCookie = UserCookie.GetCookie(user, cookie.DeviceId);

            return realCookie.Equals(cookie);
        }
Пример #3
0
 public void Read (TProtocol iprot)
 {
   TField field;
   iprot.ReadStructBegin();
   while (true)
   {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) { 
       break;
     }
     switch (field.ID)
     {
       case 0:
         if (field.Type == TType.Struct) {
           Success = new UserCookie();
           Success.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       default: 
         TProtocolUtil.Skip(iprot, field.Type);
         break;
     }
     iprot.ReadFieldEnd();
   }
   iprot.ReadStructEnd();
 }
Пример #4
0
        public static bool Validate(UserData user, UserCookie cookie)
        {
            UserCookie realCookie = UserCookie.GetCookie(user, cookie.DeviceId);

            return(realCookie.Equals(cookie));
        }