I'm trying to replicate a php login in c# - but my php is failing me, i'm just not good enough to work out how to do the equivalent in c#.
My php classes are:
function randomKey($amount)
{
$keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$randkey = "";
for ($i=0; $i<$amount; $i++)
$randkey .= substr($keyset, rand(0, strlen($keyset)-1), 1);
return $randkey;
}
public static function hashPassword($password)
{
$salt = self::randomKey(self::SALTLEN);
$site = new Sites();
$s = $site->get();
return self::hashSHA1($s->siteseed.$password.$salt.$s->siteseed).$salt;
}
I had a good crack at the first with:
public static string randomKey(string amount)
{
string keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string randKey = "";
for (int i=0; i < amount; i++)
{
randKey = randKey +
}
}
But I can't work out what the equivalent functions are. Any help really will be appreciated.
Edit: You guys have been absolutely amazing. I have one more if you don't mind. Sorry if i'm asking too much:
public static function checkPassword($password, $hash)
{
$salt = substr($hash, -self::SALTLEN);
$site = new Sites();
$s = $site->get();
return self::hashSHA1($s->siteseed.$password.$salt.$s->siteseed) === substr($hash, 0, self::SHA1LEN);
}