簡體   English   中英

使用加密哈希密碼,然后保存到數據庫

[英]Hash passwords using crypto and then save to database

目前我有此代碼

    // POST: users/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "id,naam,wachtwoord,email,isadmin")] user user)
    {
        user.wachtwoord = Crypto.HashPassword(user.wachtwoord);
        if (ModelState.IsValid)
        {
            db.users.Add(user);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(user);
    }

現在,如果我使用user.wachtwoord = crypto.hashpassword,它就會中斷

現在,我的問題是在這種情況下,通過httppost方法保存用戶密碼的正確方法是什么,以及以后如何在登錄控制器上取消哈希密碼?

問候

如果要實現自定義解決方案,則可能是:使用帶鹽的單向哈希算法,並將該值存儲在用戶表中作為用戶密碼。 您不會在登錄控制器上“散列”密碼,而是將用戶在登錄控制器中提供的密碼與salt散列在一起,然后將其與數據庫(或保存密碼的存儲庫)中的密碼進行比較。用戶憑據)。

您為什么不考慮ASP.NET身份? 在那里,您可以立即使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM