title: How to encrypt plain text to md5 / sha1 in django?
body: <p>i want to create an application that admin can make user with a new messages that encrypted into database. I have the core function and all can work properly. But, i still can't encrypt the message from text to md5/sha1. I have read and try <a href="https://stackoverflow.com/questions/4012616/python-md5-password-value">this</a> and <a href="https://docs.djangoproject.com/en/1.7/topics/auth/passwords/" rel="nofollow noreferrer">this</a>. But, i still can't do it. I'm new in django, and I'm very grateful for your response. Thank you</p>
  
  <p>This is my models:</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User) #digunakan untuk relasi ke model User (default) alias UserProfile adalah sebagai extending model
      CATEGORY_CHOICES = (
          ('admin','Admin'),
          ('user','User'),
          )
      hak_akses = models.CharField(max_length=100, choices = CATEGORY_CHOICES) 
      messages = models.CharField(max_length=100, blank=True)
      # password_pckelas = models.CharField(max_length=100, blank=True)
  
      # Override the __unicode__() method to return out something meaningful!
      def __unicode__(self):
          return self.user.username
  </code></pre>
  
  <p>This is my view function:</p>
  
  <pre><code>def tambah_user(request, template_name='form_user.html'):
      #cek session
      if 'username' in request.session and request.session['hak_akses'] == 'admin':
          #ambil dari database untuk mengaktifkan ubah_password_admin
          users = User.objects.all()
          user_form = UserForm(data=request.POST)
          profile_form = UserProfileForm(data=request.POST)
          messages = profile_form.data['messages'] #ambil messages
          if request.method == 'POST':
              if user_form.is_valid() and profile_form.is_valid():
                  #i want hash messages in here and then save into database
                  user = user_form.save()
                  user.set_password(user.password)
                  user.save()
                  profile = profile_form.save(commit=False)
                  profile.user = user
                  profile.save()
                  return redirect('manajemen_user')
              else:
                  print user_form.errors, profile_form.errors
          else:
              user_form = UserForm()
              profile_form = UserProfileForm()
  
          data = {
                  'user_form': user_form,
                  'profile_form': profile_form,
                  'object_list': users
          }
  
          return render(request, template_name, data)
      #jika session tidak ada
      else:
          return HttpResponseRedirect('/simofa/logout')
  </code></pre>
  
  <p>This is my html templates:</p>
  
  <pre><code>&lt;form name="tambah_user" class="form-horizontal style-form" method="POST"&gt;{% csrf_token %}
              &lt;div class="form-group"&gt;
                &lt;label class="col-sm-2 col-sm-2 control-label"&gt;Nama User&lt;/label&gt;
                &lt;div class="col-sm-10"&gt;
                  &lt;!-- &lt;input type="text" class='form-control'&gt; --&gt;
                  {{ user_form.username }}
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;label class="col-sm-2 col-sm-2 control-label"&gt;Password&lt;/label&gt;
                &lt;div class="col-sm-10"&gt;
                  {{ user_form.password }}
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;label class="col-sm-2 col-sm-2 control-label"&gt;Messages&lt;/label&gt;
                &lt;div class="col-sm-10"&gt;
                  {{ profile_form.messages }}
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;label class="col-sm-2 col-sm-2 control-label"&gt;Hak Akses&lt;/label&gt;
                &lt;div class="col-sm-10"&gt;
                  {{ profile_form.hak_akses }}
                  &lt;br&gt;&lt;br&gt;&lt;br&gt;
                  &lt;button type="submit" class="btn btn-theme"&gt;Submit&lt;/button&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/form&gt;
  </code></pre>