public ActionResult ChangePassword(ChangePassword _change)
        {
            if (TeacherSessionControl())
            {
                if (ModelState.IsValid)
                {
                    Password password       = new Password();
                    int      PasswordStatus = password.CheckStrength(_change.NewPassword);

                    if (PasswordStatus >= 4)
                    {
                        var UserId      = Convert.ToInt32(Session["TeacherId"]);
                        var TeacherInfo = db.Teachers.Where(x => x.Id == UserId).FirstOrDefault();

                        //encript password here
                        byte[] bytes   = Encoding.Unicode.GetBytes(_change.OldPassword);
                        byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
                        _change.OldPassword = Convert.ToBase64String(inArray);

                        if (TeacherInfo.Password == _change.OldPassword)
                        {
                            //encript password here
                            byte[] bytes2   = Encoding.Unicode.GetBytes(_change.NewPassword);
                            byte[] inArray2 = HashAlgorithm.Create("SHA1").ComputeHash(bytes2);
                            _change.NewPassword = Convert.ToBase64String(inArray2);

                            byte[] bytes3   = Encoding.Unicode.GetBytes(_change.ConfirmNewPassword);
                            byte[] inArray3 = HashAlgorithm.Create("SHA1").ComputeHash(bytes3);
                            _change.ConfirmNewPassword = Convert.ToBase64String(inArray3);

                            TeacherInfo.Password        = _change.NewPassword;
                            TeacherInfo.ConfirmPassword = _change.ConfirmNewPassword;
                            db.SaveChanges();
                            ViewBag.Message = "Password has been changed";
                            Mail _mail = new Mail();
                            _mail.SendMail(TeacherInfo.Email, "Password Change", "Dear Faculty Member, Your IIT System Login Password Has Been Changed");
                            return(View());
                        }
                        else
                        {
                            ViewBag.Message = "Password Not Match ";
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Message = "Password Not Strong ";
                        return(View());
                    }
                }
                ViewBag.Message = "Enter passwords Again";
                return(View());
            }
            else
            {
                return(TeacherLoginFaild());
            }
        }
        public ActionResult FacultyReset(ChangePassword _change)
        {
            if (_change.NewPassword != null && _change.ConfirmNewPassword != null && _change.UserId != null)
            {
                Password password       = new Password();
                int      PasswordStatus = password.CheckStrength(_change.NewPassword);

                if (PasswordStatus >= 4)
                {
                    var TeacherInfo = db.Teachers.Where(x => x.Id == _change.UserId).FirstOrDefault();

                    //encript password here
                    byte[] bytes2   = Encoding.Unicode.GetBytes(_change.NewPassword);
                    byte[] inArray2 = HashAlgorithm.Create("SHA1").ComputeHash(bytes2);
                    _change.NewPassword = Convert.ToBase64String(inArray2);

                    byte[] bytes3   = Encoding.Unicode.GetBytes(_change.ConfirmNewPassword);
                    byte[] inArray3 = HashAlgorithm.Create("SHA1").ComputeHash(bytes3);
                    _change.ConfirmNewPassword = Convert.ToBase64String(inArray3);

                    TeacherInfo.Password        = _change.NewPassword;
                    TeacherInfo.ConfirmPassword = _change.ConfirmNewPassword;
                    db.SaveChanges();
                    ViewBag.Message = "Password has been changed";
                    try
                    {
                        Mail _mail = new Mail();
                        _mail.SendMail(TeacherInfo.Email, "Password Change",
                                       "Dear Faculty Member, Your IIT System Login Password Has Been Changed");
                    }
                    catch (Exception)
                    {
                        ViewBag.Message = "Password has been changed but will not get email confirmation because of bad Internet connection ";
                        return(View());
                    }

                    var ResetList = db.ResetPassword.Where(x => x.AccountId == _change.UserId).ToList();
                    foreach (var item in ResetList)
                    {
                        item.RandomNumber = "xxx";
                    }
                    db.SaveChanges();
                    ViewBag.Message = "Password Reseted ";
                    return(View());
                }
                else
                {
                    ViewBag.Message = "Password Not Strong ";
                    return(View());
                }
            }
            ViewBag.Message = "Password Wrong ";
            return(View());
        }
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,Email,Designation,PhoneNo,Password,ConfirmPassword")] Admin admin)
        {
            Password password       = new Password();
            int      PasswordStatus = password.CheckStrength(admin.Password);

            if (ModelState.IsValid && PasswordStatus >= 4)
            {
                db.Admins.Add(admin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(admin));
        }
Exemplo n.º 4
0
        public ActionResult Register(MasterUserAccount account)
        {
            AccountDBContext DB     = new AccountDBContext();
            var      isExist        = DB.MasterUserAccounts.Count(x => x.Email == account.Email);
            Password password       = new Password();
            int      PasswordStatus = password.CheckStrength(account.Password);

            if (ModelState.IsValid)
            {
                if (PasswordStatus >= 4)
                {
                    if (isExist == 0)
                    {
                        //encript password here
                        byte[] bytes   = Encoding.Unicode.GetBytes(account.Password);
                        byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
                        account.Password        = Convert.ToBase64String(inArray);
                        account.ConfirmPassword = Convert.ToBase64String(inArray);
                        DB.MasterUserAccounts.Add(account);
                        DB.SaveChanges();
                        ModelState.Clear();
                        ViewBag.Message = "User" + account.FirstName + " " + account.LastName + " is Successfully Registered";
                        return(View());
                    }
                    else
                    {
                        ViewBag.Message = "User Already Exist";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Message = "Password Not Strong";
                    return(View());
                }
            }
            return(View());
        }
Exemplo n.º 5
0
        public ActionResult Create(Student student, HttpPostedFileBase PhotoPath2)
        {
            if (AdminSessionControl())
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        string PathAddress  = "";
                        string PathAddress2 = "";

                        Password password       = new Password();
                        int      PasswordStatus = password.CheckStrength(student.Password);
                        var      ExistEmail     = db.Students.Where(w => w.Email == student.Email);
                        var      ExistReg       = db.Students.Where(w => w.RegNo == student.RegNo).Count();

                        if (PasswordStatus < 4)
                        {
                            ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                            ViewBag.Message         = "Password Not strong: one capital letter, one small Letter, one digit and one special charecture needed ";
                            student.Password        = "";
                            student.ConfirmPassword = "";
                            return(View(student));
                        }
                        else if (PhotoPath2 == null && PhotoPath2.ContentLength < 0)
                        {
                            ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                            ViewBag.Message         = "Photo Not Acceptable";
                            student.Password        = "";
                            student.ConfirmPassword = "";
                            return(View(student));
                        }
                        else if (ExistEmail.Count() > 0)
                        {
                            ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                            ViewBag.Message         = "Email Address Already Existed";
                            student.Password        = "";
                            student.ConfirmPassword = "";
                            return(View(student));
                        }
                        else if (ExistReg > 0)
                        {
                            ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                            ViewBag.Message         = "Reg Number Already Existed";
                            student.Password        = "";
                            student.ConfirmPassword = "";
                            return(View(student));
                        }
                        else
                        {
                            //Photo Upload
                            RandomNumber _ran    = new RandomNumber();
                            string       Random  = _ran.Random(10);
                            string       Random2 = _ran.Random(10);

                            string _FileName = System.IO.Path.GetFileName(student.MobileNo + Random + Random2 + PhotoPath2.FileName);
                            PathAddress  = Path.Combine(Server.MapPath("~/ShareFiles/Students/"), _FileName);
                            PathAddress2 = "ShareFiles/Students/" + _FileName;
                            PhotoPath2.SaveAs(PathAddress);

                            //encript password here
                            byte[] bytes   = Encoding.Unicode.GetBytes(student.Password);
                            byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
                            student.Password = Convert.ToBase64String(inArray);

                            student.ConfirmPassword = Convert.ToBase64String(inArray);
                            student.PhotoPath       = PathAddress2;

                            db.Students.Add(student);
                            db.SaveChanges();
                            Mail _mail = new Mail();
                            //   _mail.SendMail(student.Email, "Account Created From IIT System", "Dear Student greeting From IIT, This email is now registered  to access IIT Course management System");


                            //Result Table will be created
                            int StudentId    = ExistEmail.FirstOrDefault().Id;
                            var ListofCourse =
                                db.Courses.Where(x => x.DepartmentId == ExistEmail.FirstOrDefault().DepartmentId).ToList();

                            foreach (var course in ListofCourse)
                            {
                                Result _result = new Result();
                                _result.StudentId = StudentId;
                                _result.CourseId  = course.Id;
                                _result.Credit    = course.Credit;
                                db.Results.Add(_result);
                                db.SaveChanges();
                            }

                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (Exception)
                    {
                        ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                        ViewBag.Message         = "Something Wrong";
                        student.Password        = "";
                        student.ConfirmPassword = "";
                        return(View(student));
                    }
                }
                ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DepartmentCode", student.DepartmentId);
                return(View(student));
            }
            else
            {
                return(AdminLoginFaild());
            }
        }
Exemplo n.º 6
0
        public ActionResult Create(Registration registration, HttpPostedFileBase PhotoPath, HttpPostedFileBase SignaturePath, HttpPostedFileBase BachelorCertificatePath)
        {
            string PhotoPath1               = "";
            string SignaturePath1           = "";
            string BachelorCertificatePath1 = "";

            if (ModelState.IsValid)
            {
                Password password       = new Password();
                int      PasswordStatus = password.CheckStrength(registration.Password);
                //check existing email
                if (PasswordStatus >= 4 && db.Registrations.Where(w => w.Email == registration.Email).ToList().Count <= 0)
                {
                    if ((PhotoPath != null && PhotoPath.ContentLength > 0 && PhotoPath.ContentLength < 100000 &&
                         (PhotoPath.ContentType == "image/jpeg" || PhotoPath.ContentType == ".png"))
                        &&
                        (SignaturePath != null && SignaturePath.ContentLength > 0 &&
                         SignaturePath.ContentLength < 80000 &&
                         (SignaturePath.ContentType == "image/jpeg" || BachelorCertificatePath.ContentType == ".png")) &&
                        (BachelorCertificatePath != null && BachelorCertificatePath.ContentLength > 0 &&
                         BachelorCertificatePath.ContentLength < 100000 &&
                         (BachelorCertificatePath.ContentType == "image/jpeg" ||
                          BachelorCertificatePath.ContentType == "png")))
                    {
                        //upload photo signature and cirtificate
                        string _PhotoFileName = System.IO.Path.GetFileName(registration.MobileNo + PhotoPath.FileName);
                        var    PhotoPath2     = Path.Combine(Server.MapPath("~/Uploads/Registration/"), _PhotoFileName);
                        PhotoPath1 = "Uploads/Registration/" + _PhotoFileName;
                        PhotoPath.SaveAs(PhotoPath2);

                        string _SignatureFileName =
                            System.IO.Path.GetFileName(registration.MobileNo + SignaturePath.FileName);
                        var SignaturePath2 = Path.Combine(Server.MapPath("~/Uploads/Registration/"), _SignatureFileName);
                        SignaturePath1 = "Uploads/Registration/" + _SignatureFileName;
                        SignaturePath.SaveAs(SignaturePath2);

                        string _BachelorFilehName =
                            System.IO.Path.GetFileName(registration.MobileNo + BachelorCertificatePath.FileName);
                        var BachelorCertificatePath2 = Path.Combine(Server.MapPath("~/Uploads/Registration/"),
                                                                    _BachelorFilehName);
                        BachelorCertificatePath1 = "Uploads/Registration/" + _BachelorFilehName;
                        PhotoPath.SaveAs(BachelorCertificatePath2);

                        registration.PhotoPath               = PhotoPath1.ToString();
                        registration.SignaturePath           = SignaturePath1.ToString();
                        registration.BachelorCertificatePath = BachelorCertificatePath1.ToString();

                        registration.PayStatus = 0;
                        registration.ShortList = 1;
                        registration.Admit     = 0;
                        db.Registrations.Add(registration);
                        db.SaveChanges();
                        return(RedirectToAction("RegistrationSuccesfull", "Applicant"));
                    }
                    else
                    {
                        ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                        ViewBag.ErrorMessage = "Insert Valid type of Photo, Signature and Cirtificate or Password is not strong";
                        return(View(registration));
                    }
                }
                else
                {
                    ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                    ViewBag.ErrorMessage = "Email Already registered";
                    return(View(registration));
                }
            }
            else
            {
                ViewBag.Bachelors = new SelectList(db.Bachelors, "Id", "Digree");
                return(View(registration));
            }
        }
Exemplo n.º 7
0
        public ActionResult Create(Admin _admin, HttpPostedFileBase PhotoPath2)
        {
            if (AdminSessionControl())
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        Password password       = new Password();
                        int      PasswordStatus = password.CheckStrength(_admin.Password);
                        var      Exist          = db.Admins.Where(w => w.Email == _admin.Email).Count();
                        string   PathAddress    = "";
                        string   PathAddress2   = "";
                        if (PhotoPath2 == null && PhotoPath2.ContentLength < 0)
                        {
                            ViewBag.Message = "Photo Not Acceptable";
                            //teacher.Password = "";
                            //teacher.ConfirmPassword = "";
                            return(View(PhotoPath2));
                        }
                        else if (PasswordStatus < 4)
                        {
                            ViewBag.Message = "Password Not Strong";
                            return(View(PhotoPath2));
                        }
                        else if (Exist > 0)
                        {
                            ViewBag.Message        = "Email Address Has Already Existed";
                            _admin.Password        = "";
                            _admin.ConfirmPassword = "";
                            return(View(_admin));
                        }
                        else
                        {
                            RandomNumber _ran   = new RandomNumber();
                            string       Random = _ran.Random(10);
                            //Photo Upload
                            string _FileName = System.IO.Path.GetFileName(_admin.LastName + Random + PhotoPath2.FileName);
                            PathAddress  = Path.Combine(Server.MapPath("~/ShareFiles/Admins/"), _FileName);
                            PathAddress2 = "ShareFiles/Admins/" + _FileName;
                            PhotoPath2.SaveAs(PathAddress);

                            //encript password here
                            byte[] bytes   = Encoding.Unicode.GetBytes(_admin.Password);
                            byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
                            _admin.Password        = Convert.ToBase64String(inArray);
                            _admin.ConfirmPassword = Convert.ToBase64String(inArray);

                            _admin.PhotoPath = PathAddress2;

                            db.Admins.Add(_admin);
                            db.SaveChanges();

                            Mail _mail = new Mail();
                            // _mail.SendMail(teacher.Email, "Account Created From IIT System", "Dear Faculty Member greeting From IIT, This email is now registered  to access IIT Course management System");

                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (Exception)
                    {
                        ViewBag.Message        = "Something Wrong";
                        _admin.Password        = "";
                        _admin.ConfirmPassword = "";
                        return(View(_admin));
                    }
                }
                ViewBag.Message = "Input Data not valide";
                return(View(_admin));
            }
            else
            {
                return(AdminLoginFaild());
            }
        }
Exemplo n.º 8
0
        public ActionResult Registration(Registration registration, HttpPostedFileBase PhotoPath, HttpPostedFileBase SignaturePath, HttpPostedFileBase BachelorCertificatePath)
        {
            // Session["CaptchaImageText"].ToString() == CaptchaText
            if (true)
            {
                string PhotoPath1               = "";
                string SignaturePath1           = "";
                string BachelorCertificatePath1 = "";

                if (true)
                {
                    //password test is it strong or not
                    Password password       = new Password();
                    int      PasswordStatus = password.CheckStrength(registration.Password);
                    if (PasswordStatus >= 4)
                    {
                        //check existing email
                        if (db.Registrations.Where(w => w.Email == registration.Email).ToList().Count <= 0)
                        {
                            if ((PhotoPath != null && PhotoPath.ContentLength > 0 && PhotoPath.ContentLength < 100000)
                                &&
                                (SignaturePath != null && SignaturePath.ContentLength > 0 &&
                                 SignaturePath.ContentLength < 80000) &&
                                (BachelorCertificatePath != null && BachelorCertificatePath.ContentLength > 0 &&
                                 BachelorCertificatePath.ContentLength < 200000))
                            {
                                //upload photo signature and cirtificate
                                string _PhotoFileName = System.IO.Path.GetFileName(registration.MobileNo + PhotoPath.FileName);
                                var    PhotoPath2     = Path.Combine(Server.MapPath("~/Uploads/Registration/"), _PhotoFileName);
                                PhotoPath1 = "Uploads/Registration/" + _PhotoFileName;
                                PhotoPath.SaveAs(PhotoPath2);

                                string _SignatureFileName =
                                    System.IO.Path.GetFileName(registration.MobileNo + SignaturePath.FileName);
                                var SignaturePath2 = Path.Combine(Server.MapPath("~/Uploads/Registration/"), _SignatureFileName);
                                SignaturePath1 = "Uploads/Registration/" + _SignatureFileName;
                                SignaturePath.SaveAs(SignaturePath2);

                                string _BachelorFilehName =
                                    System.IO.Path.GetFileName(registration.MobileNo + BachelorCertificatePath.FileName);
                                var BachelorCertificatePath2 = Path.Combine(Server.MapPath("~/Uploads/Registration/"),
                                                                            _BachelorFilehName);
                                BachelorCertificatePath1 = "Uploads/Registration/" + _BachelorFilehName;
                                BachelorCertificatePath.SaveAs(BachelorCertificatePath2);

                                registration.PhotoPath               = PhotoPath1.ToString();
                                registration.SignaturePath           = SignaturePath1.ToString();
                                registration.BachelorCertificatePath = BachelorCertificatePath1.ToString();

                                registration.PayStatus = 0;
                                registration.ShortList = 1;
                                registration.Admit     = 0;
                                db.Registrations.Add(registration);
                                db.SaveChanges();
                                return(RedirectToAction("RegistrationSuccesfull", "Applicant"));
                            }
                            else
                            {
                                ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                                ViewBag.ErrorMessage = "***Insert Valid type of Photo, Signature and Certificate";
                                return(View(registration));
                            }
                        }
                        else
                        {
                            ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                            ViewBag.ErrorMessage = "***Email Already registered";
                            return(View(registration));
                        }
                    }
                    else
                    {
                        ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                        ViewBag.ErrorMessage = "***Password is not complex enough .";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Bachelors    = new SelectList(db.Bachelors, "Id", "Digree");
                    ViewBag.ErrorMessage = "***Input data is not enough";
                    return(View(registration));
                }
            }
            else
            {
                ViewBag.Message = "Captcha Validation Failed!";
                return(View());
            }
        }