This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static HashedPassword Generate(string password) | |
{ | |
byte[] _salt = new byte[8]; | |
using (RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider()) | |
{ | |
csp.GetBytes(_salt); | |
} | |
byte[] _password = System.Text.Encoding.UTF8.GetBytes(password); | |
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(_password, _salt, 10000); | |
var _saltedPasswordHash = k1.GetBytes(24); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool Validate(string passwordHash, string saltHash, string enteredPassword) | |
{ | |
byte[] _password = System.Text.Encoding.UTF8.GetBytes(enteredPassword); | |
Rfc2898DeriveBytes keyEntered = new Rfc2898DeriveBytes(_password, Convert.FromBase64String(saltHash), 10000); | |
return Convert.ToBase64String(keyEntered.GetBytes(24)) == passwordHash; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct HashedPassword | |
{ | |
public string Password { get; set; } | |
public string Salt { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keyAndSalt = Hash.Generator.Generate("P@ssword2013"); | |
bool isEqual1 = Hash.Generator.Validate(keyAndSalt.Password, keyAndSalt.Salt, "Password2013"); | |
//isEqual1 == false | |
bool isEqual2 = Hash.Generator.Validate(keyAndSalt.Password, keyAndSalt.Salt, "P@ssword2013"); | |
//isEqual2 == true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(_password, _salt, 10000); | |
var _saltedPasswordHash = k1.GetBytes(12); | |
Debug.WriteLine(Convert.ToBase64String(_saltedPasswordHash)); | |
_saltedPasswordHash = k1.GetBytes(12); | |
Debug.WriteLine(Convert.ToBase64String(_saltedPasswordHash)); | |
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(_password, _salt, 10000); | |
_saltedPasswordHash = k2.GetBytes(24); | |
Debug.WriteLine(Convert.ToBase64String(_saltedPasswordHash)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string connectionString = "<your connectionstring here>"; | |
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); | |
if (!namespaceManager.QueueExists("orderqueue")) | |
{ | |
namespaceManager.CreateQueue("orderqueue"); | |
} | |
var Client = QueueClient.CreateFromConnectionString(connectionString, "orderqueue"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (true) | |
{ | |
BrokeredMessage message = Client.Receive(); | |
if (message != null) | |
{ | |
try | |
{ | |
var msgStream = message.GetBody<Stream>(); | |
StreamReader sr = new StreamReader(msgStream); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DataContract] | |
class Order | |
{ | |
public DateTime CreatedOn { get; set; } | |
public List<OrderRow> Orderrows { get; set; } | |
} | |
[CollectionDataContract] | |
class OrderRow | |
{ | |
[DataMember] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (int a = 0; a < 10000; a++) | |
{ | |
new Worker(this); | |
} | |
memoryLabel.Text = "Memory consumption:" + GC.GetTotalMemory(true)/1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly byte[] bLoad = new byte[99999]; | |
HostWindow _host; | |
public Worker(HostWindow host) | |
{ | |
_host = host; | |
host.ev_Click += HostEventTriggered; | |
} |
OlderNewer