简体   繁体   中英

Clean email field when new user is registering in Django?

As I know, standard new user process registration (Django 2.x) is validate email field only for exists and equals for E-mail Schemas . But users may be write e-mail address like this: JOHN_DOE@MAIL.COM (via Caps Lock) and save it to DB.

It's would be dangerous, because other user can register account for these e-mail, but in lowercase: john_doe@mail.com or similar, but still that e-mail address!

So, question now is how to (smart) clean up e-mail address when user is registering? . My ideas:

  • set email to lowercase before save to DB
  • check if it exist/unique in DB (in lowercase view, of course)

I search for best practice for solve this question, btw.

I would change it to lowercase and then save it because it looks like the least number of operations to be done. Also it should make the shortest code.

If you'll decide to check if it's unique in lowercase in DB and then save it you may end up checking DB two times (one when first check, 2nd when saving) if you'll implement it in wrong way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM