<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;Aaron Blohowiak suggests adding this as a public method in user.rb:&lt;/p&gt;

&lt;pre&gt;
def new_random_password
  self.password= Digest::SHA1.hexdigest(&quot;--#{Time.now.to_s}--#{login}--&quot;)[0,6]
  self.password_confirmation = self.password
end
&lt;/pre&gt;
&lt;p&gt;This creates an alphanumeric password and satisfies the confirmation validation.&lt;/p&gt;
&lt;p&gt;This is not what I would call random. Actually it is quite predictable. This can lead to a security hole, especially if you use this method to allow users to reset their passwords on their own. An attacker would only have to know a valid login to be able to reset the password to a value known to him, since he obviously knows the exact moment in time he submits the request.&lt;/p&gt;
&lt;p&gt;The following code should be at least slightly better:&lt;/p&gt;

&lt;p&gt;def new_random_password&lt;br /&gt;
  self.password= Digest::SHA1.hexdigest(&amp;#8220;&lt;del&gt;-#{rand.to_s}&lt;/del&gt;-#{login}&amp;#8212;&amp;#8221;)[0,6]&lt;br /&gt;
  self.password_confirmation = self.password&lt;br /&gt;
end&lt;/p&gt;</body>
  <created-at type="datetime">2008-10-24T03:51:02-07:00</created-at>
  <id type="integer">71696</id>
  <permalink>automatic-password-generation</permalink>
  <repository-id type="integer">67186</repository-id>
  <title>Automatic Password Generation</title>
  <updated-at type="datetime">2009-03-01T13:15:10-08:00</updated-at>
  <user-id type="integer">59179</user-id>
</wiki>
