1
Im asp.net中的初學者編程。我對ASP.NET中的身份與這個強大的tutorial MySQL的整合......如何在ASP.NET身份中創建默認密碼
的問題是: 如何創建一個默認密碼(例如:默認情況下)我使用此功能創建一個僱員數據後:
控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(dbemployee dbemployee)
{
if (ModelState.IsValid)
{
db.dbemployees.Add(dbemployee);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.iDept = new SelectList(db.dbtodepts, "iDept", "sDept", dbemployee.iDept);
ViewBag.iSmokers = new SelectList(db.dbtoflagies, "iFlag", "sFlag", dbemployee.iSmokers);
ViewBag.iEmpGender = new SelectList(db.dbtogenders, "iGender", "sGender", dbemployee.iEmpGender);
ViewBag.iGrade = new SelectList(db.dbtogrades, "iGrade", "sGrade", dbemployee.iGrade);
ViewBag.iJob = new SelectList(db.dbtojobs, "iJob", "sJobName", dbemployee.iJob);
ViewBag.iEmpLastEdu = new SelectList(db.dbtolasteducations, "iLastEdu", "sLastEdu", dbemployee.iEmpLastEdu);
ViewBag.iEmpMaritalStat = new SelectList(db.dbtomaritalstats, "iMaritalStat", "sMaritalStat", dbemployee.iEmpMaritalStat);
ViewBag.iEmpReligion = new SelectList(db.dbtoreligions, "iReligion", "sReligion", dbemployee.iEmpReligion);
return View(dbemployee);
}
當然,這個功能是通過自動生成的腳手架和我想象的要補充這樣的代碼:
RegisterViewModel reg = new RegisterViewModel();
reg.Password.Insert("default").GetHashCode.ToString();
正如我們所知,上面的代碼是完全錯誤的。 對不起,我的英語技能,但我希望有人瞭解我的情況。謝謝.. :)
本週*(或可能是上週)有*重複問題 - 如何生成密碼(不是默認值,這只是要求被黑客入侵)。快速和骯髒的答案是使用* old * Membership提供程序中的GeneratePassword功能。必須搜索重複找到如何做到這一點身份 –
檢查[this](http://stackoverflow.com/questions/28480167/asp-net-identity-generate-random-password)的問題,但*不* *的接受的答案。身份不會*生成密碼,它會發送重置鏈接。以明文形式發送隨機生成的密碼比安全更安全。您可以使用與MVC模板中的'Reset'頁面相同的功能來生成一次性使用的重置令牌,並將其發送給新用戶,迫使他們*選擇一個新密碼。這是更好的,因爲a)令牌不能被重用,並且b)它到期,減少了意外泄露的風險 –
Thaks對於@PanagiotisKanavos的評論...但是你能給我一些關於你的第二條評論的參考鏈接嗎?我對你的邏輯感興趣。 –