Igor Guerrero  committed cbd98ed

now using hashlib.sha1 instead of sha because sha is deprecated

  • Participants
  • Parent commits 758283e

Comments (0)

Files changed (1)

File docs/tutorial/part3.rst

 modify the model so it looks like this::
  from django.db import models
- import sha
+ import hashlib
  class User(models.Model):
      name = models.TextField()
      def check_password(self, password):
-         return sha.sha(self.password_salt + password).hexdigest() == self.password_hash
+         return hashlib.sha1(self.password_salt + password).hexdigest() == self.password_hash
 Make a schema migration that will create our two new columns (notice that
 they've both been added as ``null=True``; once they have data, we'll 
 passwords over in the forwards function::
  def forwards(self, orm):
-     import random, sha, string
+     import random, hashlib, string
      for user in orm.User.objects.all():
          user.password_salt = "".join([random.choice(string.letters) for i in range(8)])
-         user.password_hash = sha.sha(user.password_salt + user.password).hexdigest()
+         user.password_hash = hashlib.sha1(user.password_salt + user.password).hexdigest()

 Notice that we use ``orm.User`` to access the User model - this gives us the
 freezing process (there's no way to do this generally); you'll have to copy any
 code you want into the migration itself. Feel free to make them methods on
 the ``Migration`` class; South ignores everything apart from ``forwards`` and