Home > other >  Is there a way to authenticate UWP app with razor-pages created accounts?
Is there a way to authenticate UWP app with razor-pages created accounts?

Time:01-28

First, I am pretty new to C# and sorry for the bad writing, I have a razor page web app with individual accounts authentication type. Now I am working on a UWP app in which users can log in to the UWP app with the username and password provided in the razor app. Users have the same username and password for both applications. Is there any possible way to log in user to the UWP app and also limit users to access different parts of the app just like razor pages(Role manager)? Please note that the razor app is on a local server (on-premise), not a cloud, also the UWP app is on the same network so it can access the database.

What is expected to happen is that users must provide a username and password in the UWP app, they have limited access based on their roles, user names and passwords are fetched from the razor page application Db, UWP app doesn't need the ability to create or edit user accounts(it's all managed by razor app)

CodePudding user response:

Update

Please be more specific about your question next time.

if you want to hash the password in UWP apps, you could use HashAlgorithmProvider Class to hash the text. The HashAlgorithmProvider class support MD5,SHA1,SHA256,SHA384,SHA512. You could choose the same way as you choosed in your razor app.

The sample code looks like this:

 public string SampleHashMsg()
    {
        string strAlgName = HashAlgorithmNames.Md5;
        string strMsg = "thisistest";

        // Convert the message string to binary data.
        IBuffer buffUtf8Msg = CryptographicBuffer.ConvertStringToBinary(strMsg, BinaryStringEncoding.Utf8);

        // Create a HashAlgorithmProvider object.
        HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(strAlgName);

        // Demonstrate how to retrieve the name of the hashing algorithm.
        string strAlgNameUsed = objAlgProv.AlgorithmName;

        // Hash the message.
        IBuffer buffHash = objAlgProv.HashData(buffUtf8Msg);

        // Verify that the hash length equals the length specified for the algorithm.
        if (buffHash.Length != objAlgProv.HashLength)
        {
            throw new Exception("There was an error creating the hash");
        }

        // Convert the hash to a string (for display).
        string strHashBase64 = CryptographicBuffer.EncodeToHexString(buffHash);

        // Return the encoded string
        return strHashBase64;
    }

Old

Your post contains many questions. Please focus on question in one post next time.

First, you need to check the document: Use a SQL Server database in a UWP app. This tutorial shows the steps about how to connect to a sql server in UWP apps. Then you will have to write your own logic for checking the input for username and password and verify it with the data in the database.

After that, you might need to create a userinfo class which contains a flag that could indicate the role or the user after you verified the user. Before navigation, you could check the flag do decide if the user could access the page. If not, then cancel the navigation.

  • Related