Example #1
0
    def test_verify_time_based(self):
        """Test :attr:`googauth.verify_time_based`."""
        cur_time = int(time.time() / 30)
        secret_key = 'MQ3GEMTCMQ3TOOLG'
        code = googauth.generate_code(secret_key, cur_time)
        value = googauth.verify_time_based(secret_key, code)
        self.assertTrue(value == cur_time)

        cur_time = int(time.time() / 30)
        secret_key = 'G42DCMBQGJRGMZBQ'
        code = googauth.generate_code(secret_key)
        value = googauth.verify_time_based(secret_key, code)
        self.assertTrue(value != None)
Example #2
0
    def test_verify_time_based(self):
        """Test :attr:`googauth.verify_time_based`."""
        cur_time = int(time.time() / 30)
        secret_key = "MQ3GEMTCMQ3TOOLG"
        code = googauth.generate_code(secret_key, cur_time)
        value = googauth.verify_time_based(secret_key, code)
        self.assertTrue(value == cur_time)

        cur_time = int(time.time() / 30)
        secret_key = "G42DCMBQGJRGMZBQ"
        code = googauth.generate_code(secret_key)
        value = googauth.verify_time_based(secret_key, code)
        self.assertTrue(value != None)
Example #3
0
    def check_auth_code(self, auth_code):
        """
        Checks whether `auth_code` is a valid authentication code for this
        user, at the current time.
        """

        secret_key = b32encode( decrypt_value( self.encrypted_seed ) )
        val = googauth.verify_time_based( secret_key,
                                          str( auth_code ), window=5 )
        return val is not None
Example #4
0
def verify_code(username, code):
    db = get_db()

    cur = db.execute('select secret_key, last_number from googleauth where username=?', [username])
    googleauth = cur.fetchone()
    print googleauth['last_number']
    last_number = googauth.verify_time_based(googleauth['secret_key'], str(code), 6)
    print last_number
    if not last_number:
        return 'verify failed'

    if googleauth['last_number']:
        if int(last_number) <= int(googleauth['last_number']):
            return 'verify failed'

    db.execute('update googleauth set last_number=? where username=?', [last_number, username])
    db.commit()    
    return 'verify success'
Example #5
0
 def verify_otp(self, otpass):
     ref_time = int(time.time()/30)
     check_time = googauth.verify_time_based(self.secret_key, otpass)
     return (ref_time == check_time)