# Need help auth against current ASP.NET passwords using new rails site

**URL:** <https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229>\
**Category:** Rails\
**Created:** [February 15, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229 "2008-02-15T17:07:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@ray](https://www.ruby-forum.com/u/ray)\
**Post date:** [February 15, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229/1 "2008-02-15T17:07:19Z")

</div>

I have an existing [ASP.NET](http://ASP.NET) site that I am converting to rails. The  
passwords are sha1 hash generated and stored. I want the new site to  
authenticate against these passwords so the user do not have to reset  
thier passwords. How can I do this?

Current [ASP.NET](http://ASP.NET) code the generates the encrypted pass:

key =  
“3733E99C81904284624E960CEE5C472D2BC0F4379F1ECBE219ACA95B942DBE1C676CEC7B015768FE48C633B85AAF8BEBB37C567319017059F2A0C7D38FA8B92C”  
HMACSHA1 hash = new HMACSHA1();  
hash.Key = HexToByte(\_machineKey.ValidationKey);  
encodedPassword =  
Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));

ruby code using hmac-sha1 gem:  
require ‘base64’  
require ‘hmac’  
require ‘hmac-sha1’

binary\_data = @key.unpack(‘a2’\*16).map{|x| x.hex}.pack(‘c’\*16)  
encodedPassword = Base64.encode64(HMAC::SHA1::digest(binary\_data,  
@password)).strip  
puts “The ruby encodedPassword is : #{encodedPassword}”  
puts ‘My [asp.net](http://asp.net) encodedPassword is : cbRMK/fCMzu5MpMCBreQIhytKas=’

Thanks for any help

---

<div class="post-metadata">

**Author:** ![ray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@ray](https://www.ruby-forum.com/u/ray)\
**Post date:** [February 18, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229/2 "2008-02-18T15:27:08Z")

</div>

The password I was testing with was ‘ray’. Come one, someone please  
help, I can’t beleive no-one has run into this type of issue where  
they are converting an existing site and need to preserve passwords.  
I’m open to using any gem package out there so long as I can get this  
to work. Thanks

---

<div class="post-metadata">

**Author:** ![ray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@ray](https://www.ruby-forum.com/u/ray)\
**Post date:** [February 18, 2008, 5:00pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229/3 "2008-02-18T17:00:55Z")

</div>

On 18 Feb 2008, at 14:26, Ray wrote:

> The password I was testing with was ‘ray’. Come one, someone please  
> help, I can’t beleive no-one has run into this type of issue where  
> they are converting an existing site and need to preserve passwords.  
> I’m open to using any gem package out there so long as I can get this  
> to work. Thanks

Well you haven’t said what problems you are having. for starters your  
[asp.net](http://asp.net) is using \_machineKey.ValidationKey which I assume is some  
magic constant, whereas your ruby code is using @key, which you don’t  
seem to be setting anywhere

Fred

---

<div class="post-metadata">

**Author:** ![ray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@ray](https://www.ruby-forum.com/u/ray)\
**Post date:** [February 19, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229/4 "2008-02-19T14:14:24Z")

</div>

Ok, so I didn’t format the code 100% correct, the @key =  
\_machineKey.ValidationKey = key…and @password = password = ‘ray’.  
This is standard config stuff in [asp.net](http://asp.net). The problem is that I cannot  
get the ruby code give me the same encodedPassword value as the  
[asp.net](http://asp.net) code using the same password value.

Ray  
Thanks

On Feb 18, 11:00 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9a140/32.png) [@ray](https://www.ruby-forum.com/u/ray)\
**Post date:** [February 19, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/need-help-auth-against-current-asp-net-passwords-using-new-rails-site/129229/5 "2008-02-19T14:37:32Z")

</div>

On 19 Feb 2008, at 13:13, Ray wrote:

> Ok, so I didn’t format the code 100% correct, the @key =  
> \_machineKey.ValidationKey = key…and @password = password = ‘ray’.  
> This is standard config stuff in [asp.net](http://asp.net). The problem is that I cannot  
> get the ruby code give me the same encodedPassword value as the  
> [asp.net](http://asp.net) code using the same password value.

It’s kind of hard to help if the code you’re running isn’t the same as  
the code that’s in your email.  
Anyway, at least one problem area is on the line  
binary\_data = @key.unpack(‘a2’\*16).map{|x| x.hex}.pack(‘c’\*16)  
You’re only telling ruby to consume the first 32 characters of @key,  
even though @key is 128 characters long, so binary\_data only contains  
16 bytes worth of stuff, instead of 64

Fred
