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();
    }
}

2 Answers 2

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

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.