mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2026-01-01 04:23:45 +01:00
fix leaderboard looks, add OCR, make the captcha only show if you add a username and password
This commit is contained in:
15
ocr_check.py
Normal file
15
ocr_check.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import easyocr, difflib, random, string
|
||||
from constants import OCR_CHALLENGE_LENGTH
|
||||
from english_words import get_english_words_set
|
||||
|
||||
words = list(get_english_words_set(['gcide'], lower=True, alpha=True))
|
||||
reader = easyocr.Reader(['en'])
|
||||
|
||||
def check_text_similarity(image_path, text):
|
||||
result = reader.readtext(image_path, allowlist=string.ascii_letters + string.digits)
|
||||
image_text = ''.join([text[1] for text in result]).lower()
|
||||
similarity = difflib.SequenceMatcher(None, text, image_text).ratio()
|
||||
return image_text, similarity
|
||||
|
||||
def generate_challenge(username):
|
||||
return f"{username} {' '.join([random.choice(words) for _ in range(OCR_CHALLENGE_LENGTH)])}"
|
||||
Reference in New Issue
Block a user