james54
james54

Reputation: 53

How to set password to user in database directly?

I have a website for university timetable connected to microsoft sql server, there I have django table auth_user. Users can't register by themselves, university provides them with username and password. So in the table auth_user I have to fill data manually, but how can I fill the field which is responsible for password since it has to be hashed? I found only way to set password is to log in as admin, and change passwords in admin site, but that is not quite correct in terms of working with database as if I had to fill more than 100 students, it would be tiresome to do so. Maybe there is another approach to fill passwords directly in the database?

Upvotes: 1

Views: 379

Answers (1)

Iain Shelvington
Iain Shelvington

Reputation: 32294

You can set the password for a user in Django by using the set_password method

from django.contrib.auth.models import User
u = User.objects.get(username='john')
u.set_password('new password')
u.save()

Upvotes: 1

Related Questions