David542
David542

Reputation: 110382

Storing an api_key, api_pass

I want to store a user's API_KEY and API_PASSWORD, obscured in my database. I do need to be readily view them (for authentication) and to be able to display to the user if they want to view it. What would be a good way to do this?

def create_key(self, user):
    key = str(uuid.uuid4()).replace('-','')
    key_saved_in_database = # ?
    user.key = key_saved_in_database
    user.save()

def view_key(self, user):
    key_saved_in_database = user.key
    key = # ?
    return key

What are some possible ways to do this?

Upvotes: 0

Views: 144

Answers (1)

Gábor Bakos
Gábor Bakos

Reputation: 9100

A basic implementation with xoring might look like this:

def infiniteSecret(secret):
    num = 0
    while true:
        yield secret[num % len(secret)]
        num += 1
#one direction
key_saved_in_database = map(lambda a, b: a ^ b, zip(infiniteSecret(secret), key))

#other direction
key = map(lambda a, b: a ^ b, zip(infiniteSecret(secret), key_saved_in_database))

Upvotes: 1

Related Questions