I'm developing a task (nothing professional, just for learning), where I have an application that has a web application in ASP.NET and an administrator application in WPF. Both of these projects connect to the same localdb database. The task is to make sure that only non-admins can register on the web app, but admins on the WPF app also need authentication (and the Users table also has some dependencies).
So, the database is like:
UsrName UsrPwd IsAdmin
admin NULL True
nonadmin kdjfgbjk False
My issue is, that the UsrPwd
only contains the hashed passwords for the users bc of security reasons. Now. Since only the non-admins get to register on the web app, I don't know how I can add passwords to the admins because of the hashing - I added the admins via SQL queries (that's why their UsrPwd
are NULL
).
So my question is: How can I update the password for an administrator user so that I know what the password is (think of me as the system administrator providing the initial passwords), BUT only the hashed password gets saved in the database?
I thought about solving the issue by registering a user and changing the IsAdmin
to True
via SQL, but since there's some foreign key dependencies on the admin usernames, I'd rather not do that (I'd have to rebuild the database).
Is there any way I can add passwords to the admin users? I think the keyword here is some kind of code-first migration maybe (?) but I don't how to do that or if that's even the way to go.
Thank you!
EDIT
I'm not really using Identity nor OWIN or such thing, all I do is:
using (SHA512CryptoServiceProvider provider = new SHA512CryptoServiceProvider())
{
passwordBytes = provider.ComputeHash(Encoding.UTF8.GetBytes(user.UserPassword));
}
_entities.SoftwareUser.Add(new SoftwareUser
{
UsrName = user.UserName,
UsrPwd = passwordBytes,
IsAdmin = false,
});
Where SoftwareUser
is the entity generated based on the database.