# Authlogic fails on existing accounts when crypted\_password is blank

**URL:** <https://www.ruby-forum.com/t/authlogic-fails-on-existing-accounts-when-crypted-password-is-blank/178952>\
**Category:** Rails\
**Created:** [November 14, 2009, 1:02am UTC](https://www.ruby-forum.com/t/authlogic-fails-on-existing-accounts-when-crypted-password-is-blank/178952 "2009-11-14T01:02:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [November 14, 2009, 1:02am UTC](https://www.ruby-forum.com/t/authlogic-fails-on-existing-accounts-when-crypted-password-is-blank/178952/1 "2009-11-14T01:02:58Z")

</div>

I recently ran a migration to add the following to an existing user  
model:

```
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"

```

There is an existing (cleartext) password field, but authlogic doesn’t  
seem to be reading that on existing accounts. As a result, all logins  
for existing accounts fail.

How can I get authlogic to either use the cleartext passwords, or to  
bulk-populate the crypted\_password and password\_salt fields for existing  
accounts?

–  
“Oh, look: rocks!”  
– Doctor Who, “Destiny of the Daleks”

---

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [November 16, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/authlogic-fails-on-existing-accounts-when-crypted-password-is-blank/178952/2 "2009-11-16T18:09:37Z")

</div>

Todd A. Jacobs wrote:

> I recently ran a migration to add the following to an existing user  
> model:
> 
> ```
> t.string "crypted_password"
> t.string "password_salt"
> t.string "persistence_token"
> 
> ```
> 
> There is an existing (cleartext) password field, but authlogic doesn’t  
> seem to be reading that on existing accounts. As a result, all logins  
> for existing accounts fail.
> 
> How can I get authlogic to either use the cleartext passwords, or to  
> bulk-populate the crypted\_password and password\_salt fields for existing  
> accounts?
> 
> –  
> “Oh, look: rocks!”  
> – Doctor Who, “Destiny of the Daleks”

I think I’d back out the migration and redo it, writing a step in the  
migration so that you automatically populate the salt, generate and  
store the new crypted\_password for all your existing accounts when the  
migration is run (and scrub those cleartext passwords). You should be  
able to look at authlogic to see how it is done on account creation.

Then all the accounts are on the same playing field, and you don’t have  
to modify authlogic.

Test extensively of course before doing this in your ‘live’ environment.
