Click here to Skip to main content
15,894,896 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Member 245846724-Jun-18 17:45
Member 245846724-Jun-18 17:45 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Richard MacCutchan24-Jun-18 21:01
mveRichard MacCutchan24-Jun-18 21:01 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Member 245846725-Jun-18 16:27
Member 245846725-Jun-18 16:27 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Richard MacCutchan25-Jun-18 21:17
mveRichard MacCutchan25-Jun-18 21:17 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Member 245846726-Jun-18 16:17
Member 245846726-Jun-18 16:17 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Richard MacCutchan26-Jun-18 21:26
mveRichard MacCutchan26-Jun-18 21:26 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Member 245846727-Jun-18 16:08
Member 245846727-Jun-18 16:08 
GeneralRe: How to install android ndk for visual studio 2015 ? Pin
Richard MacCutchan27-Jun-18 21:06
mveRichard MacCutchan27-Jun-18 21:06 
QuestionWhy Is The Text Element Inside Of Razor Code Block Skipped During Debugging Pin
MadDashCoder23-Jun-18 13:43
MadDashCoder23-Jun-18 13:43 
AnswerRe: Why Is The Text Element Inside Of Razor Code Block Skipped During Debugging Pin
OriginalGriff23-Jun-18 19:47
mveOriginalGriff23-Jun-18 19:47 
GeneralRe: Why Is The Text Element Inside Of Razor Code Block Skipped During Debugging Pin
MadDashCoder23-Jun-18 21:31
MadDashCoder23-Jun-18 21:31 
GeneralRe: Why Is The Text Element Inside Of Razor Code Block Skipped During Debugging Pin
Pete O'Hanlon23-Jun-18 23:27
mvePete O'Hanlon23-Jun-18 23:27 
GeneralRe: Why Is The Text Element Inside Of Razor Code Block Skipped During Debugging Pin
MadDashCoder24-Jun-18 1:05
MadDashCoder24-Jun-18 1:05 
QuestionAPP Projekt call a DLL Froms Projekt Pin
Member 1368015123-Jun-18 0:52
Member 1368015123-Jun-18 0:52 
AnswerRe: APP Projekt call a DLL Froms Projekt Pin
OriginalGriff23-Jun-18 1:54
mveOriginalGriff23-Jun-18 1:54 
GeneralRe: APP Projekt call a DLL Froms Projekt Pin
Member 1368015123-Jun-18 3:23
Member 1368015123-Jun-18 3:23 
GeneralRe: APP Projekt call a DLL Froms Projekt Pin
OriginalGriff23-Jun-18 4:01
mveOriginalGriff23-Jun-18 4:01 
QuestionC# text to speech Pin
tsi clinero22-Jun-18 14:22
tsi clinero22-Jun-18 14:22 
AnswerRe: C# text to speech Pin
OriginalGriff22-Jun-18 18:10
mveOriginalGriff22-Jun-18 18:10 
GeneralRe: C# text to speech Pin
Eric Lynch22-Jun-18 23:55
Eric Lynch22-Jun-18 23:55 
GeneralRe: C# text to speech Pin
OriginalGriff23-Jun-18 0:11
mveOriginalGriff23-Jun-18 0:11 
QuestionHow do Xamarin forms connect to SQL Server ? Pin
Member 245846721-Jun-18 21:57
Member 245846721-Jun-18 21:57 
AnswerRe: How do Xamarin forms connect to SQL Server ? Pin
Richard MacCutchan21-Jun-18 22:33
mveRichard MacCutchan21-Jun-18 22:33 
AnswerRe: How do Xamarin forms connect to SQL Server ? Pin
Pete O'Hanlon22-Jun-18 1:26
mvePete O'Hanlon22-Jun-18 1:26 
QuestionComparing hashed Passwords Pin
Kevin Marois21-Jun-18 12:29
professionalKevin Marois21-Jun-18 12:29 
I'm using C# 4.5.2 & SQL Server Express 2012 RTM..

When I create a new user in my app I hash the password using
public static string Hash(string password, int iterations)
{
    //create salt
    byte[] salt;
    new RNGCryptoServiceProvider().GetBytes(salt = new byte[SaltSize]);

    //create hash
    var pbkdf2 = new Rfc2898DeriveBytes(password, salt, iterations);
    var hash = pbkdf2.GetBytes(HashSize);

    //combine salt and hash
    var hashBytes = new byte[SaltSize + HashSize];
    Array.Copy(salt, 0, hashBytes, 0, SaltSize);
    Array.Copy(hash, 0, hashBytes, SaltSize, HashSize);

    //convert to base64
    var base64Hash = Convert.ToBase64String(hashBytes);

    //format hash with extra information
    return string.Format("$MYHASH$V1${0}${1}", iterations, base64Hash);
}

Then, when I do the Login, I prompt the user's for a password, hash it using the same function, then get the user's record from the DB and compare it using this:
public static bool Verify(string password, string hashedPassword)
{
    //check hash
    if (!IsHashSupported(hashedPassword))
    {
        throw new NotSupportedException("The hashtype is not supported");
    }

    //extract iteration and Base64 string
    var splittedHashString = hashedPassword.Replace("$MYHASH$V1$", "").Split('$');
    var iterations = int.Parse(splittedHashString[0]);
    var base64Hash = splittedHashString[1];

    //get hashbytes
    var hashBytes = Convert.FromBase64String(base64Hash);

    //get salt
    var salt = new byte[SaltSize];
    Array.Copy(hashBytes, 0, salt, 0, SaltSize);

    //create hash with given salt
    var pbkdf2 = new Rfc2898DeriveBytes(password, salt, iterations);
    byte[] hash = pbkdf2.GetBytes(HashSize);

    //get result
    for (var i = 0; i < HashSize; i++)
    {
        if (hashBytes[i + SaltSize] != hash[i])
        {
            return false;
        }
    }
    return true;
}
When I try this in a console app it works fine. The hashed password is verified against what I type in.

When I retrieve the password from the DB and compare it using Verify it fails.

Anyone know what's wrong, or have a better way?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.