Re: Custom user model password is not hashed

2023-01-26 Thread Namanya Daniel
Did you try make_password before saving data from registration form ?

On Wed, 25 Jan 2023 at 18:36, Roger Mukai  wrote:

> @Tejas or @Sebs, do you still have a question how to do this? I think I
> figured it out
>
> On Tuesday, December 6, 2022 at 7:25:08 PM UTC-5 sebs...@gmail.com wrote:
>
>> Hey *Ben*, please help with the repo for the same code. I'm getting same 
>> error
>> here.
>>
>> On Saturday, 7 May 2022 at 22:37:32 UTC Tejas Agrawal wrote:
>>
>>> Hey Benjamin, can you please share your github repo for the same code.
>>> I'm also getting the same error in one of my project, can't figure out how
>>> to solve it.
>>>
>>> On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30
>>> benjamin...@gmail.com wrote:
>>>
 The problem was, when creating a custom user, one has to define a
 custom model form and model admin that handles the password properly. After
 that it was solved.

 Thank you.

 On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne 
 wrote:

> Try to debug and check what your password value is after the
> set_password() statement.  Also have you checked the database after trying
> to create a user with the new method? It should be hashed in the database.
> This is stuff that should "just work" in django (it's regulated by the
> AbstractBaseUser and is the same that I am using in a project).
>
> You did restart the django shell after changing the code?
>
> 2015-11-12 16:44 GMT+01:00 Benjamin Smith :
>
>> I have changed user.set_password(self.cleaned_data["password"]) to 
>> user.set_password(password).
>> But I am getting the same result.
>>
>> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne <
>> andrea...@suitopia.com> wrote:
>>
>>> As aRkadeFR says, you seam to have mixed code there
>>>
>>> The row:
>>> user.set_password(self.cleaned_data["password"])
>>>
>>> is taken from a form somewhere and won't work. It should instead be
>>> :
>>> user.set_password(password)
>>>
>>> I suppose the password is going through to the create method via the
>>> kwargs argument at the end of you create method. But if you change like 
>>> I
>>> said, everything should work.
>>>
>>>
>>> Med vänliga hälsningar,
>>>
>>> Andréas Kühne
>>> Software Development Manager
>>> Suitopia Scandinavia AB
>>>
>>> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>>>
 Hello,

 I don't quite get the code in your method: '
 MyUserManager.create_user':
 user.set_password(self.cleaned_data["password"])

 You're in your Manager method but call self.cleaned_data ?

 You can set a breakpoint inside your method with pdb to see
 what's going on with your fields?


 On 11/12/2015 04:11 PM, Benjamin Smith wrote:

 I have my own custom User model, and its own Manger too.

 Models:

 class MyUser(AbstractBaseUser, PermissionsMixin):
 email = models.EmailField(max_length=255, unique=True)
 first_name = models.CharField(max_length=35)
 last_name = models.CharField(max_length=35)
 username = models.CharField(max_length=70, unique=True)
 date_of_birth = models.DateField()
 is_active = models.BooleanField(default=True)
 is_admin = models.BooleanField(default=False)

 @property
 def is_staff(self):
 return self.is_admin

 def get_full_name(self):
 return ('%s %s') % (self.first_name, self.last_name)

 def get_short_name(self):
 return self.username

 objects = MyUserManager()
 USERNAME_FIELD = 'email'
 REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
 'date_of_birth']


 Manager:

 class MyUserManager(BaseUserManager):
 def create_user(self, email, first_name, last_name, username,
 date_of_birth, password=None, **kwargs):
 if not email:
 raise ValueError('User must have an email address')

 user = self.model(
 email=self.normalize_email(email),
 first_name=first_name,
 last_name=last_name,
 username=username,
 date_of_birth=date_of_birth,
 **kwargs
 )
 user.set_password(self.cleaned_data["password"])
 user.save(using=self._db)
 return user

 def create_superuser(self, email, first_name, last_name,
 username, date_of_birth, password, **kwargs):
 user = self.create_user(
 email,
   

Re: Custom user model password is not hashed

2023-01-26 Thread James
Yup, 100% correct. Glad to hear you fixed it. Custom user models that 
inherit from the abstractbaseuser class can be a little tricky at first.

On Friday, November 13, 2015 at 5:41:09 AM UTC-7 benjamin...@gmail.com 
wrote:

> The problem was, when creating a custom user, one has to define a custom 
> model form and model admin that handles the password properly. After that 
> it was solved.
>
> Thank you.
>
> On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne  
> wrote:
>
>> Try to debug and check what your password value is after the 
>> set_password() statement.  Also have you checked the database after trying 
>> to create a user with the new method? It should be hashed in the database. 
>> This is stuff that should "just work" in django (it's regulated by the 
>> AbstractBaseUser and is the same that I am using in a project).
>>
>> You did restart the django shell after changing the code?
>>
>> 2015-11-12 16:44 GMT+01:00 Benjamin Smith :
>>
>>> I have changed user.set_password(self.cleaned_data["password"]) to 
>>> user.set_password(password). 
>>> But I am getting the same result.
>>>
>>> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  
>>> wrote:
>>>
 As aRkadeFR says, you seam to have mixed code there

 The row:
 user.set_password(self.cleaned_data["password"])

 is taken from a form somewhere and won't work. It should instead be : 
 user.set_password(password)

 I suppose the password is going through to the create method via the 
 kwargs argument at the end of you create method. But if you change like I 
 said, everything should work.


 Med vänliga hälsningar,

 Andréas Kühne
 Software Development Manager
 Suitopia Scandinavia AB

 2015-11-12 16:20 GMT+01:00 aRkadeFR :

> Hello,
>
> I don't quite get the code in your method: '
> MyUserManager.create_user':
> user.set_password(self.cleaned_data["password"])
>
> You're in your Manager method but call self.cleaned_data ?
>
> You can set a breakpoint inside your method with pdb to see
> what's going on with your fields?
>
>
> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>
> I have my own custom User model, and its own Manger too.
>
> Models:
>
> class MyUser(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(max_length=255, unique=True)
> first_name = models.CharField(max_length=35)
> last_name = models.CharField(max_length=35)
> username = models.CharField(max_length=70, unique=True)
> date_of_birth = models.DateField()
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> @property
> def is_staff(self):
> return self.is_admin
>
> def get_full_name(self):
> return ('%s %s') % (self.first_name, self.last_name)
>
> def get_short_name(self):
> return self.username
>
> objects = MyUserManager()
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 
> 'date_of_birth']
>
>
> Manager:
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, first_name, last_name, username, 
> date_of_birth, password=None, **kwargs):
> if not email:
> raise ValueError('User must have an email address')
>
> user = self.model(
> email=self.normalize_email(email),
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> **kwargs
> )
> user.set_password(self.cleaned_data["password"])
> user.save(using=self._db)
> return user
>
> def create_superuser(self, email, first_name, last_name, username, 
> date_of_birth, password, **kwargs):
> user = self.create_user(
> email,
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> password=password,
> is_superuser=True,
> **kwargs
> )
> user.is_admin = True
> user.save(using=self._db)
> return user
>
>
> Everything works when creating a new user without any errors. But when 
> I try to login I can't. So I checked the user's email and password to 
> confirm. Then I noticed that the password is displayed as plain text (eg. 
> *strongpassword)*, and when changed the admin form to get the hashed 
> password using *ReadOnlyPasswordHashField()* I get an error inside 
> the password field, even though I used *set_password()* for the 
> Manger inside the 

Re: Custom user model password is not hashed

2023-01-25 Thread Roger Mukai
@Tejas or @Sebs, do you still have a question how to do this? I think I 
figured it out

On Tuesday, December 6, 2022 at 7:25:08 PM UTC-5 sebs...@gmail.com wrote:

> Hey *Ben*, please help with the repo for the same code. I'm getting same 
> error 
> here.
>
> On Saturday, 7 May 2022 at 22:37:32 UTC Tejas Agrawal wrote:
>
>> Hey Benjamin, can you please share your github repo for the same code. 
>> I'm also getting the same error in one of my project, can't figure out how 
>> to solve it.
>>
>> On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30 benjamin...@gmail.com 
>> wrote:
>>
>>> The problem was, when creating a custom user, one has to define a custom 
>>> model form and model admin that handles the password properly. After that 
>>> it was solved.
>>>
>>> Thank you.
>>>
>>> On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne  
>>> wrote:
>>>
 Try to debug and check what your password value is after the 
 set_password() statement.  Also have you checked the database after trying 
 to create a user with the new method? It should be hashed in the database. 
 This is stuff that should "just work" in django (it's regulated by the 
 AbstractBaseUser and is the same that I am using in a project).

 You did restart the django shell after changing the code?

 2015-11-12 16:44 GMT+01:00 Benjamin Smith :

> I have changed user.set_password(self.cleaned_data["password"]) to 
> user.set_password(password). 
> But I am getting the same result.
>
> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  > wrote:
>
>> As aRkadeFR says, you seam to have mixed code there
>>
>> The row:
>> user.set_password(self.cleaned_data["password"])
>>
>> is taken from a form somewhere and won't work. It should instead be : 
>> user.set_password(password)
>>
>> I suppose the password is going through to the create method via the 
>> kwargs argument at the end of you create method. But if you change like 
>> I 
>> said, everything should work.
>>
>>
>> Med vänliga hälsningar,
>>
>> Andréas Kühne
>> Software Development Manager
>> Suitopia Scandinavia AB
>>
>> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>>
>>> Hello,
>>>
>>> I don't quite get the code in your method: '
>>> MyUserManager.create_user':
>>> user.set_password(self.cleaned_data["password"])
>>>
>>> You're in your Manager method but call self.cleaned_data ?
>>>
>>> You can set a breakpoint inside your method with pdb to see
>>> what's going on with your fields?
>>>
>>>
>>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>>
>>> I have my own custom User model, and its own Manger too.
>>>
>>> Models:
>>>
>>> class MyUser(AbstractBaseUser, PermissionsMixin):
>>> email = models.EmailField(max_length=255, unique=True)
>>> first_name = models.CharField(max_length=35)
>>> last_name = models.CharField(max_length=35)
>>> username = models.CharField(max_length=70, unique=True)
>>> date_of_birth = models.DateField()
>>> is_active = models.BooleanField(default=True)
>>> is_admin = models.BooleanField(default=False)
>>>
>>> @property
>>> def is_staff(self):
>>> return self.is_admin
>>>
>>> def get_full_name(self):
>>> return ('%s %s') % (self.first_name, self.last_name)
>>>
>>> def get_short_name(self):
>>> return self.username
>>>
>>> objects = MyUserManager()
>>> USERNAME_FIELD = 'email'
>>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 
>>> 'date_of_birth']
>>>
>>>
>>> Manager:
>>>
>>> class MyUserManager(BaseUserManager):
>>> def create_user(self, email, first_name, last_name, username, 
>>> date_of_birth, password=None, **kwargs):
>>> if not email:
>>> raise ValueError('User must have an email address')
>>>
>>> user = self.model(
>>> email=self.normalize_email(email),
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> **kwargs
>>> )
>>> user.set_password(self.cleaned_data["password"])
>>> user.save(using=self._db)
>>> return user
>>>
>>> def create_superuser(self, email, first_name, last_name, 
>>> username, date_of_birth, password, **kwargs):
>>> user = self.create_user(
>>> email,
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> password=password,
>>> is_superuser=True,
>>> **kwargs
>>> 

Re: Custom user model password is not hashed

2022-12-06 Thread Sage
Hey *Ben*, please help with the repo for the same code. I'm getting same error 
here.

On Saturday, 7 May 2022 at 22:37:32 UTC Tejas Agrawal wrote:

> Hey Benjamin, can you please share your github repo for the same code. I'm 
> also getting the same error in one of my project, can't figure out how to 
> solve it.
>
> On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30 benjamin...@gmail.com 
> wrote:
>
>> The problem was, when creating a custom user, one has to define a custom 
>> model form and model admin that handles the password properly. After that 
>> it was solved.
>>
>> Thank you.
>>
>> On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne  
>> wrote:
>>
>>> Try to debug and check what your password value is after the 
>>> set_password() statement.  Also have you checked the database after trying 
>>> to create a user with the new method? It should be hashed in the database. 
>>> This is stuff that should "just work" in django (it's regulated by the 
>>> AbstractBaseUser and is the same that I am using in a project).
>>>
>>> You did restart the django shell after changing the code?
>>>
>>> 2015-11-12 16:44 GMT+01:00 Benjamin Smith :
>>>
 I have changed user.set_password(self.cleaned_data["password"]) to 
 user.set_password(password). 
 But I am getting the same result.

 On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  
 wrote:

> As aRkadeFR says, you seam to have mixed code there
>
> The row:
> user.set_password(self.cleaned_data["password"])
>
> is taken from a form somewhere and won't work. It should instead be : 
> user.set_password(password)
>
> I suppose the password is going through to the create method via the 
> kwargs argument at the end of you create method. But if you change like I 
> said, everything should work.
>
>
> Med vänliga hälsningar,
>
> Andréas Kühne
> Software Development Manager
> Suitopia Scandinavia AB
>
> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>
>> Hello,
>>
>> I don't quite get the code in your method: '
>> MyUserManager.create_user':
>> user.set_password(self.cleaned_data["password"])
>>
>> You're in your Manager method but call self.cleaned_data ?
>>
>> You can set a breakpoint inside your method with pdb to see
>> what's going on with your fields?
>>
>>
>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>
>> I have my own custom User model, and its own Manger too.
>>
>> Models:
>>
>> class MyUser(AbstractBaseUser, PermissionsMixin):
>> email = models.EmailField(max_length=255, unique=True)
>> first_name = models.CharField(max_length=35)
>> last_name = models.CharField(max_length=35)
>> username = models.CharField(max_length=70, unique=True)
>> date_of_birth = models.DateField()
>> is_active = models.BooleanField(default=True)
>> is_admin = models.BooleanField(default=False)
>>
>> @property
>> def is_staff(self):
>> return self.is_admin
>>
>> def get_full_name(self):
>> return ('%s %s') % (self.first_name, self.last_name)
>>
>> def get_short_name(self):
>> return self.username
>>
>> objects = MyUserManager()
>> USERNAME_FIELD = 'email'
>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 
>> 'date_of_birth']
>>
>>
>> Manager:
>>
>> class MyUserManager(BaseUserManager):
>> def create_user(self, email, first_name, last_name, username, 
>> date_of_birth, password=None, **kwargs):
>> if not email:
>> raise ValueError('User must have an email address')
>>
>> user = self.model(
>> email=self.normalize_email(email),
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> **kwargs
>> )
>> user.set_password(self.cleaned_data["password"])
>> user.save(using=self._db)
>> return user
>>
>> def create_superuser(self, email, first_name, last_name, 
>> username, date_of_birth, password, **kwargs):
>> user = self.create_user(
>> email,
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> password=password,
>> is_superuser=True,
>> **kwargs
>> )
>> user.is_admin = True
>> user.save(using=self._db)
>> return user
>>
>>
>> Everything works when creating a new user without any errors. But 
>> when I try to login I can't. So I checked the user's email and password 
>> to 
>> confirm. 

Re: Custom user model password is not hashed

2022-05-07 Thread Tejas Agrawal
Hey Benjamin, can you please share your github repo for the same code. I'm 
also getting the same error in one of my project, can't figure out how to 
solve it.

On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30 benjamin...@gmail.com 
wrote:

> The problem was, when creating a custom user, one has to define a custom 
> model form and model admin that handles the password properly. After that 
> it was solved.
>
> Thank you.
>
> On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne  
> wrote:
>
>> Try to debug and check what your password value is after the 
>> set_password() statement.  Also have you checked the database after trying 
>> to create a user with the new method? It should be hashed in the database. 
>> This is stuff that should "just work" in django (it's regulated by the 
>> AbstractBaseUser and is the same that I am using in a project).
>>
>> You did restart the django shell after changing the code?
>>
>> 2015-11-12 16:44 GMT+01:00 Benjamin Smith :
>>
>>> I have changed user.set_password(self.cleaned_data["password"]) to 
>>> user.set_password(password). 
>>> But I am getting the same result.
>>>
>>> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  
>>> wrote:
>>>
 As aRkadeFR says, you seam to have mixed code there

 The row:
 user.set_password(self.cleaned_data["password"])

 is taken from a form somewhere and won't work. It should instead be : 
 user.set_password(password)

 I suppose the password is going through to the create method via the 
 kwargs argument at the end of you create method. But if you change like I 
 said, everything should work.


 Med vänliga hälsningar,

 Andréas Kühne
 Software Development Manager
 Suitopia Scandinavia AB

 2015-11-12 16:20 GMT+01:00 aRkadeFR :

> Hello,
>
> I don't quite get the code in your method: '
> MyUserManager.create_user':
> user.set_password(self.cleaned_data["password"])
>
> You're in your Manager method but call self.cleaned_data ?
>
> You can set a breakpoint inside your method with pdb to see
> what's going on with your fields?
>
>
> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>
> I have my own custom User model, and its own Manger too.
>
> Models:
>
> class MyUser(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(max_length=255, unique=True)
> first_name = models.CharField(max_length=35)
> last_name = models.CharField(max_length=35)
> username = models.CharField(max_length=70, unique=True)
> date_of_birth = models.DateField()
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> @property
> def is_staff(self):
> return self.is_admin
>
> def get_full_name(self):
> return ('%s %s') % (self.first_name, self.last_name)
>
> def get_short_name(self):
> return self.username
>
> objects = MyUserManager()
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 
> 'date_of_birth']
>
>
> Manager:
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, first_name, last_name, username, 
> date_of_birth, password=None, **kwargs):
> if not email:
> raise ValueError('User must have an email address')
>
> user = self.model(
> email=self.normalize_email(email),
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> **kwargs
> )
> user.set_password(self.cleaned_data["password"])
> user.save(using=self._db)
> return user
>
> def create_superuser(self, email, first_name, last_name, username, 
> date_of_birth, password, **kwargs):
> user = self.create_user(
> email,
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> password=password,
> is_superuser=True,
> **kwargs
> )
> user.is_admin = True
> user.save(using=self._db)
> return user
>
>
> Everything works when creating a new user without any errors. But when 
> I try to login I can't. So I checked the user's email and password to 
> confirm. Then I noticed that the password is displayed as plain text (eg. 
> *strongpassword)*, and when changed the admin form to get the hashed 
> password using *ReadOnlyPasswordHashField()* I get an error inside 
> the password field, even though I used *set_password()* for the 
> Manger 

Re: Custom user model password is not hashed

2015-11-13 Thread Benjamin Smith
The problem was, when creating a custom user, one has to define a custom
model form and model admin that handles the password properly. After that
it was solved.

Thank you.

On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne 
wrote:

> Try to debug and check what your password value is after the
> set_password() statement.  Also have you checked the database after trying
> to create a user with the new method? It should be hashed in the database.
> This is stuff that should "just work" in django (it's regulated by the
> AbstractBaseUser and is the same that I am using in a project).
>
> You did restart the django shell after changing the code?
>
> 2015-11-12 16:44 GMT+01:00 Benjamin Smith :
>
>> I have changed user.set_password(self.cleaned_data["password"]) to 
>> user.set_password(password).
>> But I am getting the same result.
>>
>> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne <
>> andreas.ku...@suitopia.com> wrote:
>>
>>> As aRkadeFR says, you seam to have mixed code there
>>>
>>> The row:
>>> user.set_password(self.cleaned_data["password"])
>>>
>>> is taken from a form somewhere and won't work. It should instead be :
>>> user.set_password(password)
>>>
>>> I suppose the password is going through to the create method via the
>>> kwargs argument at the end of you create method. But if you change like I
>>> said, everything should work.
>>>
>>>
>>> Med vänliga hälsningar,
>>>
>>> Andréas Kühne
>>> Software Development Manager
>>> Suitopia Scandinavia AB
>>>
>>> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>>>
 Hello,

 I don't quite get the code in your method: 'MyUserManager.create_user':
 user.set_password(self.cleaned_data["password"])

 You're in your Manager method but call self.cleaned_data ?

 You can set a breakpoint inside your method with pdb to see
 what's going on with your fields?


 On 11/12/2015 04:11 PM, Benjamin Smith wrote:

 I have my own custom User model, and its own Manger too.

 Models:

 class MyUser(AbstractBaseUser, PermissionsMixin):
 email = models.EmailField(max_length=255, unique=True)
 first_name = models.CharField(max_length=35)
 last_name = models.CharField(max_length=35)
 username = models.CharField(max_length=70, unique=True)
 date_of_birth = models.DateField()
 is_active = models.BooleanField(default=True)
 is_admin = models.BooleanField(default=False)

 @property
 def is_staff(self):
 return self.is_admin

 def get_full_name(self):
 return ('%s %s') % (self.first_name, self.last_name)

 def get_short_name(self):
 return self.username

 objects = MyUserManager()
 USERNAME_FIELD = 'email'
 REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
 'date_of_birth']


 Manager:

 class MyUserManager(BaseUserManager):
 def create_user(self, email, first_name, last_name, username,
 date_of_birth, password=None, **kwargs):
 if not email:
 raise ValueError('User must have an email address')

 user = self.model(
 email=self.normalize_email(email),
 first_name=first_name,
 last_name=last_name,
 username=username,
 date_of_birth=date_of_birth,
 **kwargs
 )
 user.set_password(self.cleaned_data["password"])
 user.save(using=self._db)
 return user

 def create_superuser(self, email, first_name, last_name, username,
 date_of_birth, password, **kwargs):
 user = self.create_user(
 email,
 first_name=first_name,
 last_name=last_name,
 username=username,
 date_of_birth=date_of_birth,
 password=password,
 is_superuser=True,
 **kwargs
 )
 user.is_admin = True
 user.save(using=self._db)
 return user


 Everything works when creating a new user without any errors. But when
 I try to login I can't. So I checked the user's email and password to
 confirm. Then I noticed that the password is displayed as plain text (eg.
 *strongpassword)*, and when changed the admin form to get the hashed
 password using *ReadOnlyPasswordHashField()* I get an error inside the
 password field, even though I used *set_password()* for the Manger
 inside the *create_user()* function.

 *Invalid password format or unknown hashing algorithm*


 However, if I manually do *set_password('strongpassword')* for that
 user inside the console, then only the password is hashed. Could you please
 help me solve this problem. Thank 

Re: Custom user model password is not hashed

2015-11-12 Thread Andreas Kuhne
Try to debug and check what your password value is after the set_password()
statement.  Also have you checked the database after trying to create a
user with the new method? It should be hashed in the database. This is
stuff that should "just work" in django (it's regulated by the
AbstractBaseUser and is the same that I am using in a project).

You did restart the django shell after changing the code?

2015-11-12 16:44 GMT+01:00 Benjamin Smith :

> I have changed user.set_password(self.cleaned_data["password"]) to 
> user.set_password(password).
> But I am getting the same result.
>
> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  > wrote:
>
>> As aRkadeFR says, you seam to have mixed code there
>>
>> The row:
>> user.set_password(self.cleaned_data["password"])
>>
>> is taken from a form somewhere and won't work. It should instead be :
>> user.set_password(password)
>>
>> I suppose the password is going through to the create method via the
>> kwargs argument at the end of you create method. But if you change like I
>> said, everything should work.
>>
>>
>> Med vänliga hälsningar,
>>
>> Andréas Kühne
>> Software Development Manager
>> Suitopia Scandinavia AB
>>
>> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>>
>>> Hello,
>>>
>>> I don't quite get the code in your method: 'MyUserManager.create_user':
>>> user.set_password(self.cleaned_data["password"])
>>>
>>> You're in your Manager method but call self.cleaned_data ?
>>>
>>> You can set a breakpoint inside your method with pdb to see
>>> what's going on with your fields?
>>>
>>>
>>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>>
>>> I have my own custom User model, and its own Manger too.
>>>
>>> Models:
>>>
>>> class MyUser(AbstractBaseUser, PermissionsMixin):
>>> email = models.EmailField(max_length=255, unique=True)
>>> first_name = models.CharField(max_length=35)
>>> last_name = models.CharField(max_length=35)
>>> username = models.CharField(max_length=70, unique=True)
>>> date_of_birth = models.DateField()
>>> is_active = models.BooleanField(default=True)
>>> is_admin = models.BooleanField(default=False)
>>>
>>> @property
>>> def is_staff(self):
>>> return self.is_admin
>>>
>>> def get_full_name(self):
>>> return ('%s %s') % (self.first_name, self.last_name)
>>>
>>> def get_short_name(self):
>>> return self.username
>>>
>>> objects = MyUserManager()
>>> USERNAME_FIELD = 'email'
>>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
>>> 'date_of_birth']
>>>
>>>
>>> Manager:
>>>
>>> class MyUserManager(BaseUserManager):
>>> def create_user(self, email, first_name, last_name, username,
>>> date_of_birth, password=None, **kwargs):
>>> if not email:
>>> raise ValueError('User must have an email address')
>>>
>>> user = self.model(
>>> email=self.normalize_email(email),
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> **kwargs
>>> )
>>> user.set_password(self.cleaned_data["password"])
>>> user.save(using=self._db)
>>> return user
>>>
>>> def create_superuser(self, email, first_name, last_name, username,
>>> date_of_birth, password, **kwargs):
>>> user = self.create_user(
>>> email,
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> password=password,
>>> is_superuser=True,
>>> **kwargs
>>> )
>>> user.is_admin = True
>>> user.save(using=self._db)
>>> return user
>>>
>>>
>>> Everything works when creating a new user without any errors. But when I
>>> try to login I can't. So I checked the user's email and password to
>>> confirm. Then I noticed that the password is displayed as plain text (eg.
>>> *strongpassword)*, and when changed the admin form to get the hashed
>>> password using *ReadOnlyPasswordHashField()* I get an error inside the
>>> password field, even though I used *set_password()* for the Manger
>>> inside the *create_user()* function.
>>>
>>> *Invalid password format or unknown hashing algorithm*
>>>
>>>
>>> However, if I manually do *set_password('strongpassword')* for that
>>> user inside the console, then only the password is hashed. Could you please
>>> help me solve this problem. Thank you.
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To 

Re: Custom user model password is not hashed

2015-11-12 Thread Benjamin Smith
I have changed user.set_password(self.cleaned_data["password"]) to
user.set_password(password).
But I am getting the same result.

On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne 
wrote:

> As aRkadeFR says, you seam to have mixed code there
>
> The row:
> user.set_password(self.cleaned_data["password"])
>
> is taken from a form somewhere and won't work. It should instead be :
> user.set_password(password)
>
> I suppose the password is going through to the create method via the
> kwargs argument at the end of you create method. But if you change like I
> said, everything should work.
>
>
> Med vänliga hälsningar,
>
> Andréas Kühne
> Software Development Manager
> Suitopia Scandinavia AB
>
> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>
>> Hello,
>>
>> I don't quite get the code in your method: 'MyUserManager.create_user':
>> user.set_password(self.cleaned_data["password"])
>>
>> You're in your Manager method but call self.cleaned_data ?
>>
>> You can set a breakpoint inside your method with pdb to see
>> what's going on with your fields?
>>
>>
>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>
>> I have my own custom User model, and its own Manger too.
>>
>> Models:
>>
>> class MyUser(AbstractBaseUser, PermissionsMixin):
>> email = models.EmailField(max_length=255, unique=True)
>> first_name = models.CharField(max_length=35)
>> last_name = models.CharField(max_length=35)
>> username = models.CharField(max_length=70, unique=True)
>> date_of_birth = models.DateField()
>> is_active = models.BooleanField(default=True)
>> is_admin = models.BooleanField(default=False)
>>
>> @property
>> def is_staff(self):
>> return self.is_admin
>>
>> def get_full_name(self):
>> return ('%s %s') % (self.first_name, self.last_name)
>>
>> def get_short_name(self):
>> return self.username
>>
>> objects = MyUserManager()
>> USERNAME_FIELD = 'email'
>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
>> 'date_of_birth']
>>
>>
>> Manager:
>>
>> class MyUserManager(BaseUserManager):
>> def create_user(self, email, first_name, last_name, username,
>> date_of_birth, password=None, **kwargs):
>> if not email:
>> raise ValueError('User must have an email address')
>>
>> user = self.model(
>> email=self.normalize_email(email),
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> **kwargs
>> )
>> user.set_password(self.cleaned_data["password"])
>> user.save(using=self._db)
>> return user
>>
>> def create_superuser(self, email, first_name, last_name, username,
>> date_of_birth, password, **kwargs):
>> user = self.create_user(
>> email,
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> password=password,
>> is_superuser=True,
>> **kwargs
>> )
>> user.is_admin = True
>> user.save(using=self._db)
>> return user
>>
>>
>> Everything works when creating a new user without any errors. But when I
>> try to login I can't. So I checked the user's email and password to
>> confirm. Then I noticed that the password is displayed as plain text (eg.
>> *strongpassword)*, and when changed the admin form to get the hashed
>> password using *ReadOnlyPasswordHashField()* I get an error inside the
>> password field, even though I used *set_password()* for the Manger
>> inside the *create_user()* function.
>>
>> *Invalid password format or unknown hashing algorithm*
>>
>>
>> However, if I manually do *set_password('strongpassword')* for that user
>> inside the console, then only the password is hashed. Could you please help
>> me solve this problem. Thank you.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> aRkadeFR
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to 

Re: Custom user model password is not hashed

2015-11-12 Thread Andreas Kuhne
As aRkadeFR says, you seam to have mixed code there

The row:
user.set_password(self.cleaned_data["password"])

is taken from a form somewhere and won't work. It should instead be :
user.set_password(password)

I suppose the password is going through to the create method via the kwargs
argument at the end of you create method. But if you change like I said,
everything should work.


Med vänliga hälsningar,

Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB

2015-11-12 16:20 GMT+01:00 aRkadeFR :

> Hello,
>
> I don't quite get the code in your method: 'MyUserManager.create_user':
> user.set_password(self.cleaned_data["password"])
>
> You're in your Manager method but call self.cleaned_data ?
>
> You can set a breakpoint inside your method with pdb to see
> what's going on with your fields?
>
>
> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>
> I have my own custom User model, and its own Manger too.
>
> Models:
>
> class MyUser(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(max_length=255, unique=True)
> first_name = models.CharField(max_length=35)
> last_name = models.CharField(max_length=35)
> username = models.CharField(max_length=70, unique=True)
> date_of_birth = models.DateField()
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> @property
> def is_staff(self):
> return self.is_admin
>
> def get_full_name(self):
> return ('%s %s') % (self.first_name, self.last_name)
>
> def get_short_name(self):
> return self.username
>
> objects = MyUserManager()
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
> 'date_of_birth']
>
>
> Manager:
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, first_name, last_name, username,
> date_of_birth, password=None, **kwargs):
> if not email:
> raise ValueError('User must have an email address')
>
> user = self.model(
> email=self.normalize_email(email),
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> **kwargs
> )
> user.set_password(self.cleaned_data["password"])
> user.save(using=self._db)
> return user
>
> def create_superuser(self, email, first_name, last_name, username,
> date_of_birth, password, **kwargs):
> user = self.create_user(
> email,
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> password=password,
> is_superuser=True,
> **kwargs
> )
> user.is_admin = True
> user.save(using=self._db)
> return user
>
>
> Everything works when creating a new user without any errors. But when I
> try to login I can't. So I checked the user's email and password to
> confirm. Then I noticed that the password is displayed as plain text (eg.
> *strongpassword)*, and when changed the admin form to get the hashed
> password using *ReadOnlyPasswordHashField()* I get an error inside the
> password field, even though I used *set_password()* for the Manger inside
> the *create_user()* function.
>
> *Invalid password format or unknown hashing algorithm*
>
>
> However, if I manually do *set_password('strongpassword')* for that user
> inside the console, then only the password is hashed. Could you please help
> me solve this problem. Thank you.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> aRkadeFR
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5644AE3A.5050609%40arkade.info
> 

Re: Custom user model password is not hashed

2015-11-12 Thread Thorsten Sanders

If you wanna set the password yourself you need to generate it:

https://docs.djangoproject.com/en/1.8/topics/auth/passwords/

scroll down to the bottom and have a lookt at make_password



Am 12.11.2015 um 16:11 schrieb Benjamin Smith:

I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name,
username, date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when 
I try to login I can't. So I checked the user's email and password to 
confirm. Then I noticed that the password is displayed as plain text 
(eg. *strongpassword)*, and when changed the admin form to get the 
hashed password using *ReadOnlyPasswordHashField()* I get an error 
inside the password field, even though I used *set_password()* for the 
Manger inside the *create_user()* function.


/Invalid password format or unknown hashing algorithm/


However, if I manually do *set_password('strongpassword')* for that 
user inside the console, then only the password is hashed. Could you 
please help me solve this problem. Thank you.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5644AF6C.1090304%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Custom user model password is not hashed

2015-11-12 Thread aRkadeFR

Hello,

I don't quite get the code in your method: 'MyUserManager.create_user':
user.set_password(self.cleaned_data["password"])

You're in your Manager method but call self.cleaned_data ?

You can set a breakpoint inside your method with pdb to see
what's going on with your fields?


On 11/12/2015 04:11 PM, Benjamin Smith wrote:

I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name,
username, date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when 
I try to login I can't. So I checked the user's email and password to 
confirm. Then I noticed that the password is displayed as plain text 
(eg. *strongpassword)*, and when changed the admin form to get the 
hashed password using *ReadOnlyPasswordHashField()* I get an error 
inside the password field, even though I used *set_password()* for the 
Manger inside the *create_user()* function.


/Invalid password format or unknown hashing algorithm/


However, if I manually do *set_password('strongpassword')* for that 
user inside the console, then only the password is hashed. Could you 
please help me solve this problem. Thank you.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
aRkadeFR

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5644AE3A.5050609%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Custom user model password is not hashed

2015-11-12 Thread Benjamin Smith
I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name, username,
date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when I
try to login I can't. So I checked the user's email and password to
confirm. Then I noticed that the password is displayed as plain text (eg.
*strongpassword)*, and when changed the admin form to get the hashed
password using *ReadOnlyPasswordHashField()* I get an error inside the
password field, even though I used *set_password()* for the Manger inside
the *create_user()* function.

*Invalid password format or unknown hashing algorithm*


However, if I manually do *set_password('strongpassword')* for that user
inside the console, then only the password is hashed. Could you please help
me solve this problem. Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.