# Encrypt a user password using "Authlogic"

**URL:** <https://www.ruby-forum.com/t/encrypt-a-user-password-using-authlogic/182887>\
**Category:** Rails\
**Created:** [February 4, 2010, 11:45am UTC](https://www.ruby-forum.com/t/encrypt-a-user-password-using-authlogic/182887 "2010-02-04T11:45:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 4, 2010, 11:45am UTC](https://www.ruby-forum.com/t/encrypt-a-user-password-using-authlogic/182887/1 "2010-02-04T11:45:46Z")

</div>

Hi,  
I have a csv file which have the user detail. I want to migrate this  
information into the “users” table.  
My application use “Authlogic” for user aunthentication so I have to  
encrypt the password during migration. I have written the script which  
is reading the csv file and adds the record into “users” table, it is  
working fine. But I am not able to encrypt the password.  
I am doing like this:-  
user=User.find(1)  
user.password=“password”  
user.save

My users.rb as follows :-  
“acts\_as\_authentic do |c|  
c.transition\_from\_restful\_authentication = true  
end”

It is creating the entry in users table with crypted\_password is equal  
to “password”.  
How should I fix this?  
Any help appreciated?

Thanks,  
Tushar G.

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 4, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/encrypt-a-user-password-using-authlogic/182887/2 "2010-02-04T12:47:33Z")

</div>

Hi,  
I have midifed my code like this it seems that it is encrypting the  
password.  
But the password is coming as a log string.  
My updated code is :-  
user=User.find(2)  
user.password=“password”  
user.password\_confirmation=“password”  
user.save

It is encrypting the password like this:-  
“9b2dcddea0f2ecab44c195b36035cab8da14e719b51c696e704f885f29f8310939fb980d11434c545b43cfa9390b1e6b3d5dbb82f97289da9a1740eadda6b5ae”

Is it right?

Thanks,  
Tushar

> My users.rb as follows :-  
> “acts\_as\_authentic do |c|  
> c.transition\_from\_restful\_authentication = true  
> end”
> 
> It is creating the entry in users table with crypted\_password is equal  
> to “password”.  
> How should I fix this?  
> Any help appreciated?
> 
> Thanks,  
> Tushar G.

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [February 4, 2010, 12:49pm UTC](https://www.ruby-forum.com/t/encrypt-a-user-password-using-authlogic/182887/3 "2010-02-04T12:49:21Z")

</div>

Hi,  
I have modified my code and it is encrypting the  
password.  
But the password is coming a very long string.  
My updated code is :-  
user=User.find(2)  
user.password=“password”  
user.password\_confirmation=“password”  
user.save

It is encrypting the password like this:-  
“9b2dcddea0f2ecab44c195b36035cab8da14e719b51c696e704f885f29f8310939fb980d11434c545b43cfa9390b1e6b3d5dbb82f97289da9a1740eadda6b5ae”

Is it right?

Thanks,  
Tushar

> > It is creating the entry in users table with crypted\_password is equal  
> > to “password”.  
> > How should I fix this?  
> > Any help appreciated?
> > 
> > Thanks,  
> > Tushar G.
