如何在 ASP.NET 网页中进行 MD5 散列 (razor syntax/cshtml)

How to do MD5 hashing in ASP.NET web pages (razor syntax/cshtml)

我正在使用 RAZOR 语法 (cshtml) 将 PHP 页面转换为 ASP.NET 网页。 我知道如何在 c# 中使用 MD5,但在 RAZOR 语法中无法获得任何帮助。 谁能帮我把下面的 PHP 行转换成 Razor 语法。

if(isset($_POST['login-check']) && $_POST['login-check'] == 'request'){

$CampusName = $_POST['campusid'];
$studentID = $_POST['studentid'];
$pass = $_POST['password'];
$salt = "portal";
$pass = md5($pass.''.$salt);

}

这行代码

$pass = md5($pass.''.$salt);

此致。

Razor 语法是 C#。但是您不应该使用 MD5 来散列密码。这是一个broken algorithm. The Web Pages framework includes a Crypto helper class with a HashPassword method that uses a proper algorithm: https://www.mikesdotnetting.com/article/200/the-simplemembershipprovider-secure-passwords-and-the-crypto-helper。如果您不想使用 SimpleMembershipProvider 来管理用户帐户,您可以自己使用辅助方法:

if(IsPost()){
    var CampusName = Request["campusid"];
    var studentID = Request["studentid"];
    var pass = Crypto.HashPassword(Request["password"]);
    // no need for messing about with salts, already taken care of
}

然后您使用 VerifyHashedPassword 方法将提交的密码与您存储的散列值进行比较。