Skip to content

Commit

Permalink
Update helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhorasani authored May 6, 2024
1 parent c2b7473 commit 61d7adc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion streamlit_authenticator/utilities/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
Libraries imported:
- string: Module providing support for ASCII character encoding.
- random: Module generating random characters.
- captcha: Module generating captcha images.
"""

import string
import random
from captcha.image import ImageCaptcha

class Helpers:
"""
Expand All @@ -32,4 +34,19 @@ def generate_random_pw(cls, length: int=16) -> str:
"""
letters = string.ascii_letters + string.digits
return ''.join(random.choice(letters) for i in range(length)).replace(' ','')

@classmethod
def generate_captcha(cls) -> tuple:
"""
Generates a captcha image.
Returns
-------
int
The randomly generated four digit captcha.
ImageCaptcha
The randomly generated captcha object.
"""
image = ImageCaptcha(width=120, height=75)
random_digit = random.choices(string.digits, k=4)
return random_digit, image.generate(random_digit)

0 comments on commit 61d7adc

Please sign in to comment.