Created
September 25, 2009 02:39
-
-
Save voxxit/193250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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