From a601309d6d88979c6b707c1e6e6a6d5c02225c1b Mon Sep 17 00:00:00 2001 From: exdal <63502313+exdal@users.noreply.github.com> Date: Sun, 15 Sep 2024 15:29:23 +0300 Subject: [PATCH] DDD-DDD regex (#1) 2fa auth gibi numeric regex --------- Co-authored-by: Sefa --- common_words.txt | 1035 ---------------------------------------- src/database/verify.rs | 19 +- 2 files changed, 3 insertions(+), 1051 deletions(-) delete mode 100644 common_words.txt diff --git a/common_words.txt b/common_words.txt deleted file mode 100644 index adbe0f6..0000000 --- a/common_words.txt +++ /dev/null @@ -1,1035 +0,0 @@ -a -able -about -above -accept -across -act -actually -add -admit -afraid -after -afternoon -again -against -age -ago -agree -ah -ahead -air -all -allow -almost -alone -along -already -alright -also -although -always -am -amaze -an -and -anger -angry -animal -annoy -another -answer -any -anymore -anyone -anything -anyway -apartment -apparently -appear -approach -are -area -aren't -arent -arm -around -arrive -as -ask -asleep -ass -at -attack -attempt -attention -aunt -avoid -away -baby -back -bad -bag -ball -band -bar -barely -bathroom -be -beat -beautiful -became -because -become -bed -bedroom -been -before -began -begin -behind -believe -bell -beside -besides -best -better -between -big -bit -bite -black -blink -block -blonde -blood -blue -blush -body -book -bore -both -bother -bottle -bottom -box -boy -boyfriend -brain -break -breakfast -breath -breathe -bright -bring -broke -broken -brother -brought -brown -brush -build -burn -burst -bus -business -busy -but -buy -by -call -calm -came -can -can't -cant -car -card -care -carefully -carry -case -cat -catch -caught -cause -cell -chair -chance -change -chase -check -cheek -chest -child -children -chuckle -city -class -clean -clear -climb -close -clothes -coffee -cold -college -color -come -comment -complete -completely -computer -concern -confuse -consider -continue -control -conversation -cool -corner -couch -could -couldn't -couldnt -counter -couple -course -cover -crack -crazy -cross -crowd -cry -cup -cut -cute -dad -damn -dance -dark -date -daughter -day -dead -deal -dear -death -decide -deep -definitely -desk -did -didn't -didnt -die -different -dinner -direction -disappear -do -doctor -does -doesn't -doesnt -dog -don't -done -dont -door -doubt -down -drag -draw -dream -dress -drink -drive -drop -drove -dry -during -each -ear -early -easily -easy -eat -edge -either -else -empty -end -enjoy -enough -enter -entire -escape -especially -even -evening -eventually -ever -every -everyone -everything -exactly -except -excite -exclaim -excuse -expect -explain -expression -eye -eyebrow -face -fact -fall -family -far -fast -father -fault -favorite -fear -feel -feet -fell -felt -few -field -fight -figure -fill -finally -find -fine -finger -finish -fire -first -fit -five -fix -flash -flip -floor -fly -focus -follow -food -foot -for -force -forget -form -forward -found -four -free -friend -from -front -frown -fuck -full -fun -funny -further -game -gasp -gave -gaze -gently -get -giggle -girl -girlfriend -give -given -glad -glance -glare -glass -go -God -gone -gonna -good -got -gotten -grab -great -green -greet -grey -grin -grip -groan -ground -group -grow -guard -guess -gun -guy -had -hadn't -hadnt -hair -half -hall -hallway -hand -handle -hang -happen -happy -hard -has -hate -have -haven't -havent -he -he'd -he's -head -hear -heard -heart -heavy -hed -held -hell -hello -help -her -here -herself -hes -hey -hi -hide -high -him -himself -his -hit -hold -home -hope -horse -hospital -hot -hour -house -how -however -hug -huge -huh -human -hundred -hung -hurry -hurt -I -I'd -I'll -I'm -I've -ice -Id -idea -if -ignore -Ill -Im -imagine -immediately -important -in -inside -instead -interest -interrupt -into -is -isn't -isnt -it -it's -its -its -Ive -jacket -jeans -jerk -job -join -joke -jump -just -keep -kept -key -kick -kid -kill -kind -kiss -kitchen -knee -knew -knock -know -known -lady -land -large -last -late -laugh -lay -lead -lean -learn -least -leave -led -left -leg -less -let -letter -lie -life -lift -light -like -line -lip -listen -little -live -lock -locker -long -look -lose -lost -lot -loud -love -low -lunch -mad -made -make -man -manage -many -mark -marry -match -matter -may -maybe -me -mean -meant -meet -memory -men -mention -met -middle -might -mind -mine -minute -mirror -miss -mom -moment -money -month -mood -more -morning -most -mother -mouth -move -movie -mr -mrs -much -mum -mumble -music -must -mutter -my -myself -name -near -nearly -neck -need -nervous -never -new -next -nice -night -no -nod -noise -none -normal -nose -not -note -nothing -notice -now -number -obviously -of -off -offer -office -often -oh -okay -old -on -once -one -only -onto -open -or -order -other -our -out -outside -over -own -pack -pain -paint -pair -pants -paper -parents -park -part -party -pass -past -pause -pay -people -perfect -perhaps -person -phone -pick -picture -piece -pink -piss -place -plan -play -please -pocket -point -police -pop -position -possible -power -practically -present -press -pretend -pretty -probably -problem -promise -pull -punch -push -put -question -quick -quickly -quiet -quietly -quite -race -rain -raise -ran -rang -rather -reach -read -ready -real -realize -really -reason -recognize -red -relationship -relax -remain -remember -remind -repeat -reply -respond -rest -return -ride -right -ring -road -rock -roll -room -rose -round -rub -run -rush -sad -safe -said -same -sat -save -saw -say -scare -school -scream -search -seat -second -see -seem -seen -self -send -sense -sent -serious -seriously -set -settle -seven -several -shadow -shake -share -she -she'd -she's -shed -shes -shift -shirt -shit -shock -shoe -shook -shop -short -shot -should -shoulder -shouldn't -shouldnt -shout -shove -show -shower -shrug -shut -sick -side -sigh -sight -sign -silence -silent -simply -since -single -sir -sister -sit -situation -six -skin -sky -slam -sleep -slightly -slip -slow -slowly -small -smell -smile -smirk -smoke -snap -so -soft -softly -some -somehow -someone -something -sometimes -somewhere -son -song -soon -sorry -sort -sound -space -speak -spend -spent -spoke -spot -stair -stand -star -stare -start -state -stay -step -stick -still -stomach -stood -stop -store -story -straight -strange -street -strong -struggle -stuck -student -study -stuff -stupid -such -suck -sudden -suddenly -suggest -summer -sun -suppose -sure -surprise -surround -sweet -table -take -taken -talk -tall -teacher -team -tear -teeth -tell -ten -than -thank -that -that's -thats -the -their -them -themselves -then -there -there's -theres -these -they -they'd -they're -theyd -theyre -thick -thing -think -third -this -those -though -thought -three -threw -throat -through -throw -tie -tight -time -tiny -tire -to -today -together -told -tomorrow -tone -tongue -tonight -too -took -top -totally -touch -toward -town -track -trail -train -tree -trip -trouble -TRUE -trust -truth -try -turn -TV -twenty -two -type -uncle -under -understand -until -up -upon -us -use -usual -usually -very -visit -voice -wait -wake -walk -wall -want -warm -warn -was -wasn't -wasnt -watch -water -wave -way -we -we'll -we're -we've -wear -week -weird -well -well -went -were -were -weren't -werent -wet -weve -what -what's -whatever -whats -when -where -whether -which -while -whisper -white -who -whole -why -wide -wife -will -wind -window -wipe -wish -with -within -without -woke -woman -women -won't -wonder -wont -wood -word -wore -work -world -worry -worse -would -wouldn't -wouldnt -wow -wrap -write -wrong -yeah -year -yell -yes -yet -you -you'd -you'll -you're -you've -youd -youll -young -your -youre -yourself -youve diff --git a/src/database/verify.rs b/src/database/verify.rs index f648bb4..53b91e6 100644 --- a/src/database/verify.rs +++ b/src/database/verify.rs @@ -19,7 +19,7 @@ pub async fn verify_discord( } if let Some(one_time_token) = one_time_token { - let regex = Regex::new(r"^([A-z']+-){5}[A-z']+$").unwrap(); + let regex = Regex::new(r"^\d{3}-\d{3}$").unwrap(); if !regex.is_match(one_time_token) { return Err(Error::TokenInvalid); } @@ -188,22 +188,9 @@ pub async fn get_ckey_by_discord_id(discord_id: &str, pool: &MySqlPool) -> Resul } async fn generate_one_time_token(connection: &mut PoolConnection) -> String { - let common_words = include_str!("../../common_words.txt"); - let common_words = common_words.lines().collect::>(); - loop { - let mut token = String::new(); - - for _ in 0..6 { - token.push_str(common_words[rand::thread_rng().gen_range(0..common_words.len())]); - token.push('-'); - } - - token.pop(); - - if token.len() > 100 { - token.truncate(100); - } + let token: u32 = rand::thread_rng().gen_range(1..=999_999); + let token = format!("{:03}-{:03}", token / 1_000, token % 1_000); if let Err(Error::TokenInvalid) = discord_id_by_token(&token, false, connection).await { return token;