Search code examples
entity-frameworkauthenticationpassword-encryptionpassword-hashasp.net-core-3.1

How to manage (add) users for ASP.NET Core 3.1 application externally


I'm sorry here will be no code provided, because I'm totally missing the idea.

Context: I develop two applications, both ASP.NET Core 3.1, lets call them A and B.

A is a website, exposed to the internet. Only users with a valid user account shall have access. There shall be no possibility to register one user within application A.

B is an internal (intranet) website. (Authentication with Active Directory.) From application B I want to be able to create users for application A.

Application A has NOTHING to do with Active Directory, I use the normal inbuild user administration of ASP.NET core.

Is it possible to enter the users to Application A from Application B by using the Entity Framework? Or is there any better approach? If it works with the Entity Framework, how will I be able to get the Salt value which is used by application A to salt the passwords?

For clarification: I have no questions about authentication or registration of users for application B, that all works.


Solution

  • You can easily create a hash of a password with the following method

    public string CreateHash(TUser user, string password)
    {
        var hasher = new PasswordHasher<TUser>();
    
        return (hasher.HashPassword(user, password));
    }
    

    The user object must not even be the one of which you want to change the password.