views:

276

answers:

3

I want a Registration Form with only email + password. I am thinking to insert automatically email in username field. So, for eash user, I will have this:

username: [email protected]

password: mypassword

email: [email protected]

Of course email + password will be used in login process.

Is it a good solution to having 2 fields with the same value ? Or is there a more sofisticated solution ?

Thanks :)

A: 

Are you asking whether or not it's a good idea to login with an e-mail instead of a username? In that case, yes, that's a very good solution. It makes it easier for the user to remember which email they registered with.

I would change the caption of 'username' to 'email', though.

Jonatan Littke
I am asking whether is a good idea to insert email in 2 field ( username and email ). Both are required. Or is there an alternative solution :) ?
xRobot
+1  A: 

Probably not a good idea to circumvent the expected regex validation on username which is r'^\w+$' (so no @ or ., obviously). Also, there's a 30 character limit on username, so lots of email addresses won't fit.

You should write a custom auth backend that authenticates based on the actual email field - many people do this, so you can probably find samples on djangosnippets.

Two things to keep in mind - by default, the email field is non-unique. Also, you are almost definitely going to break the admin app, so you'll need to do some jiggery pokery if you want to use contrib.admin.

ozan
To resolve I can insert random string in username field and "unique=True" in Registration Form's email. Is a good idea ?
xRobot