Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created September 25, 2009 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voxxit/193250 to your computer and use it in GitHub Desktop.
Save voxxit/193250 to your computer and use it in GitHub Desktop.
# This will generate something like "jfonda51", and a password like "0be21405590f",
# which is completely secure.
if client.first_name? && client.last_name?
new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
# Replace the username, if it is blank
if client.username.blank?
# Check for existing usernames, and regenerate until unique
until Client.exists?(:username => new_credentials.username) == false
new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
end
client.username = new_credentials.username
end
# Replace the password, if it is blank
if client.crypted_password.blank?
client.password = new_credentials.password
client.password_confirmation = new_credentials.password
end
# Save the client
client.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment