इस प्रयास करें:
web.config:
<authentication mode="Forms">
<forms loginUrl="~/Admin/LogOn" timeout="2880" >
<credentials passwordFormat="SHA1">
<user name="admin" password="5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"/>
</credentials>
</forms>
</authentication>
पासवर्ड स्वरूप SHA1 पर सेट किया जाता है, तो आपका पासवर्ड स्पष्ट पाठ में नहीं दिखाई देंगे। हालांकि यह अभी भी क्रैक किया जा सकता है। उदाहरण के लिए ऑनलाइन SHA1 जनरेटर का उपयोग करके अपना खुद का हैश उत्पन्न करें।
loginUrl आपके लॉगिन पेज (duh: P) का मार्ग है, इसलिए यदि यह अलग है तो इसे बदलें।
CredentialsViewModel: आपका प्रवेश दृश्य के लिए
public class CredentialsViewModel
{
[Required]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
}
देखें मॉडल।
AdminController:
public ViewResult LogOn()
{
return View();
}
[HttpPost]
public ActionResult LogOn(CredentialsViewModel model, string returnUrl)
{
if(ModelState.IsValid)
{
if(FormsAuthentication.Authenticate(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
}
else
{
ModelState.AddModelError("", "Incorrect username or password");
}
}
return View();
}
[Authorize]
public ViewResult Index()
{
return View();
}
तो लॉगऑन क्रिया देखने से पारित कर दिया साख को प्रमाणित करेगा; web.config डेटा के साथ इसकी तुलना करें।
महत्वपूर्ण हिस्सा यहां [Authorize] विशेषता है जो अनधिकृत उपयोगकर्ताओं से पहुंच को रोक देगा।
यदि आप कोड नमूने प्रदान करते हैं तो आपको बेहतर उत्तर मिलेंगे। – robrich
@robrich आपको इस प्रश्न के लिए कोड क्यों चाहिए? – tito11
क्यों वोट नीचे ??? – tito11