【问题标题】:How to do MD5 hashing in ASP.NET web pages (razor syntax/cshtml)如何在 ASP.NET 网页中进行 MD5 散列(razor 语法/cshtml)
【发布时间】:2018-07-24 09:25:52
【问题描述】:

我正在使用 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 asp.net-webpages


    【解决方案1】:

    Razor 语法是 C#。但是您不应该使用 MD5 来散列密码。这是broken algorithm。 Web Pages 框架包括一个Crypto 辅助类和一个使用适当算法的HashPassword 方法: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 方法将提交的密码与您存储的哈希值进行比较。

    【讨论】:

    • 谢谢 Mike Brind,我明白了。
    猜你喜欢
    • 2016-06-02
    • 2011-06-23
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多