django / channels

Developer-friendly asynchrony for Django
https://channels.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.11k stars 800 forks source link

Authentication Hash Problem #1823

Closed prxful closed 2 years ago

prxful commented 2 years ago

Hi Dev, I'm use Django 4.0.3 & i see some error.. well we can;t say error but its bug

Django = 4.0.3 Linux x64 1 In this.. Create user generate password field with encryption. So, we can auth & login successfully

2

Column 2 & 3 created by python manage.py shell Column 1 created by view.py

Default User.object.create_user() in view.py dont make hash password & save plain text.. So, it's unsuccessful when we do login.

Please Fix

almazkun commented 2 years ago

Good day!

Proper way of setting password for Django User is: 'user.set_password("password")'and 'user.save()'. This way the password will be hashed.

For more information: https://stackoverflow.com/questions/30466191/django-set-password-isnt-hashing-passwords

prxful commented 2 years ago

Good day!

Proper way of setting password for Django User is: 'user.set_password("password")'and 'user.save()'. This way the password will be hashed.

For more information: https://stackoverflow.com/questions/30466191/django-set-password-isnt-hashing-passwords

Nope.. I try this.. not working in Django 4.0.3 you can try too .. in View.py not using in Shell

The Bug is.. user.set_password() not hash the normal text. for this u need to use make_password to make them hash then store via user.set_password() & user.save()

almazkun commented 2 years ago

@MrR1pp3r, could you please take a look at this example: git@github.com:almazkun/django_password_hash.git?

There are 2 endpoints to create a user. It is saving hashed passwords.

Or please share your code. It will be easier to debug.

Thank you! =)

prxful commented 2 years ago

@almazkun, i see your repo.. i use the same method here u go user i send you video too.. wait for 10 minutes

prxful commented 2 years ago

@almazkun

https://user-images.githubusercontent.com/48425460/160585005-6c6c3d36-c533-44fe-a0d7-0f5b1bbf3886.mp4

@MrR1pp3r, could you please take a look at this example: git@github.com:almazkun/django_password_hash.git?

There are 2 endpoints to create a user. It is saving hashed passwords.

Or please share your code. It will be easier to debug.

Thank you! =)

prxful commented 2 years ago

@MrR1pp3r, could you please take a look at this example: git@github.com:almazkun/django_password_hash.git?

There are 2 endpoints to create a user. It is saving hashed passwords.

Or please share your code. It will be easier to debug.

Thank you! =)

Problem is I can create user via terminal .. but i can't make hash password via drf api

carbon

almazkun commented 2 years ago

Good day! =)

Maybe this is the problem:

Screen Shot 2022-04-04 at 6 50 27 PM

Could you try this instead: user.set_password(raw_password)?

like here: https://github.com/almazkun/django_startapp/blob/05eb1f9b4177346fb92170b3651ca5b5a756558d/apps/accounts/models.py#L23

prxful commented 2 years ago

Good day! =)

Maybe this is the problem: Screen Shot 2022-04-04 at 6 50 27 PM Could you try this instead: user.set_password(raw_password)?

like here: https://github.com/almazkun/django_startapp/blob/05eb1f9b4177346fb92170b3651ca5b5a756558d/apps/accounts/models.py#L23

I try every thing.. set_password(password), make_hash(password) & user.password = make_hash(password)

I find the solution but.. i need to call create_user() twice ....

First, models.py where i make custom user method.. & the next call in Serializer.. when create user.

Actually i use ModelSerializer So, i predict.. i need to just use META & FIELDS,, but later i override CREATE() & BOOOOOM its working.

`def create(self, validated_data): username = validated_data.pop('username') password = validated_data.pop('password')

user = get_user_model().objects.create_user(username=username, **validated_data) user.set_password(password) user.save() return user`

& Thanx For The Code. ( I learn about customForm )

almazkun commented 2 years ago

Would you mind closing the issue? :)