Hafidz Fairiz
Hafidz Fairiz

Reputation: 65

How to Create default password in ASP.NET Identity

Im a beginner programming in asp.net. I have mysql integration for the identity in ASP.NET with this powerful tutorial...

The question is: How to Create a default password (ex: default) after i create an employee data with this function:

Controller:

[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);
        }

Of course this function is autogenerated by scaffolding, and my imagine is should add the code like this:

RegisterViewModel reg = new RegisterViewModel(); 
          reg.Password.Insert("default").GetHashCode.ToString();

And as we know, the code above is totally wrong.. Sorry for my english skill, but i hope someone understand my case. Thanks.. :)

Upvotes: 1

Views: 1738

Answers (1)

Maciej
Maciej

Reputation: 93

ASP.NET Identity does not include default password creation methods, as it relays on password reset links, that are way safer way of handling passwords. Have you considered that approach in your app?

Upvotes: 2

Related Questions