4

I want to move from ASP.NET MVC Identity to node.js. I have the following field in my database:

PasswordHash: AOCB5TrZGusq9ZUdYd/w/u7GUZTPOMG7JhFd4JgS0gLOulL8QjZRbl4T6sPXwD3lfQ==

The password is asdfgak. I have no idea how to use this PasswordHash and how to get the hash and salt from it to login users from node.js.

I saw this answer but it didn't help at all, the output from this was the following:

A+w9Dyfupc+dMkViA0eYF4ol7HhdIfVPct6o47a+n5M=

Here is the code that I have in my MVC project, if that helps:

public class ApplicationUser : IdentityUser
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }

    // my custom fields like username, gender...
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("Personal", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}
Community
  • 1
  • 1
Luca Steeb
  • 1,795
  • 4
  • 23
  • 44

2 Answers2

4

Ok, I found this module where you can even choose between sync & async, it's awesome:

https://www.npmjs.com/package/aspnet-identity-pw

Luca Steeb
  • 1,795
  • 4
  • 23
  • 44
1

Old question, but for anyone ending up here just wanting to verify a password from existing aspnet identity hashed password with modern js, it can be done like this:

import crypto from 'crypto'

const hashed = Buffer.from('AOCB5TrZGusq9ZUdYd/w/u7GUZTPOMG7JhFd4JgS0gLOulL8QjZRbl4T6sPXwD3lfQ==', 'base64')
const salt = hashed.slice(1, 17)
const bytes = hashed.slice(17, 49)
const key = crypto.pbkdf2Sync('asdfgak', salt, 1000, 32, 'sha1')
const match = key.equals(bytes)
fiddur
  • 1,768
  • 15
  • 11