Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to generate unique validation code for gift cards. #379

Conversation

Kotik112
Copy link
Contributor

@Kotik112 Kotik112 commented Dec 5, 2023

When purchasing gift cards, a unique validation code is required that the user will be able to use to redeem said gift card.
This commit/function aims to be able to generate those validation codes.

Please provide feedback if this is safe usage and/or if the length of the validation code needs to be altered. Maybe I need to implement some sort of List() that keeps track of all validation codes to "ensure" that the validation code is indeed unique?

from secrets import token_hex


def generate_gift_card_code(length=16):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length=10 is probably enough (number of alternatives is then about 10^12). But I don't really care that much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd only get a probable collision after about a million gift cards.

@BerglundDaniel BerglundDaniel merged commit bc83736 into makerspace:master Dec 6, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants