# How to check user typed email is exist in database or not and raise a validationError?

**URL:** https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769
**Category:** Using Django
**Created:** [April 1, 2020, 1:50pm UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769 "2020-04-01T13:50:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mtrazakhan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtrazakhan/32/1026_2.png) [@mtrazakhan](https://forum.djangoproject.com/u/mtrazakhan)
#### Post date: [April 1, 2020, 1:50pm UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/1 "2020-04-01T13:50:32Z")

</div>

I am implementing Django Password Reset to send a recovery password link when the user type his/her email id using django.contrib.auth.urls, which works as perfectly.

This is from Django Documentation,

> If the email address provided does not exist in the system, the user is inactive, or has an unusable password, the user will still be redirected to this view but no email will be sent.

My question is,

how to add EmailValidation to check if the user typed email exists in the database or not and raise ValidationError.

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [April 1, 2020, 7:54pm UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/2 "2020-04-01T19:54:13Z")

</div>

Also from the documentation at: [https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.views.PasswordResetView](https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.views.PasswordResetView)

If the email address provided does not exist in the system, this view won’t send an email, but the user won’t receive any error message either. **This prevents information leaking to potential attackers.** If you want to provide an error message in this case, you can subclass [`PasswordResetForm`](https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.forms.PasswordResetForm) and use the `form_class` attribute.

(Emphasis mine) If you notice from other sites you may use, this is a common practice. A site generally doesn’t want to advertise what accounts are active - it helps reduce the surface area on which an attack can be made.

---

<div class="post-metadata">

### Author: ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)
#### Post date: [April 2, 2020, 10:25am UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/3 "2020-04-02T10:25:48Z")

</div>

If you want to add such validation to the password reset form, I suggest not doing it. By validating email address on that form you’re giving potential hackers a valuable information about existence/non-existence of a particular email address in your database.

---

<div class="post-metadata">

### Author: ![mtrazakhan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtrazakhan/32/1026_2.png) [@mtrazakhan](https://forum.djangoproject.com/u/mtrazakhan)
#### Post date: [April 2, 2020, 10:34am UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/4 "2020-04-02T10:34:35Z")

</div>

very thanks for your reply

---

<div class="post-metadata">

### Author: ![mtrazakhan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtrazakhan/32/1026_2.png) [@mtrazakhan](https://forum.djangoproject.com/u/mtrazakhan)
#### Post date: [April 2, 2020, 10:37am UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/5 "2020-04-02T10:37:20Z")

</div>

Please help me to solve this issue:[How can i get selected value in user update form?](https://forum.djangoproject.com/t/how-can-i-get-selected-value-in-user-update-form/1747)

---

<div class="post-metadata">

### Author: ![mtrazakhan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtrazakhan/32/1026_2.png) [@mtrazakhan](https://forum.djangoproject.com/u/mtrazakhan)
#### Post date: [July 9, 2020, 10:31am UTC](https://forum.djangoproject.com/t/how-to-check-user-typed-email-is-exist-in-database-or-not-and-raise-a-validationerror/1769/6 "2020-07-09T10:31:33Z")

</div>

Please reply on this thread if you know:- [how can I also show stock message with there location like “Added %s items to stock with %s location”?](https://forum.djangoproject.com/t/how-can-i-also-show-stock-message-with-there-location-like-added-s-items-to-stock-with-s-location/3349)
