Esempio n. 1
0
        public ActionResult pwdpolicy(Pwdpolicycon pwd)
        {
            try
            {
                paresetEntities db = new paresetEntities();

                var obj = db.Pwdpolicies.ToList();
                obj[0].Isenabel = pwd.pwdminlen;
                obj[1].Isenabel = pwd.capfirst;
                obj[2].Isenabel = pwd.spclchar;
                obj[3].Isenabel = pwd.lastpwd;
                //obj.Emailotp = confauthoptionsobj.emailotp;
                //obj.Charesq = confauthoptionsobj.challengequestions;
                //obj.Smsotp = confauthoptionsobj.smsotp;
                foreach (var m in obj)
                {
                    db.Entry(m).CurrentValues.SetValues(m);
                    db.SaveChanges();
                }

                ModelState.Clear();
                ViewBag.Message = "Success";
                return(View(pwd));
            }

            catch (Exception ex)
            {
                ViewBag.Message = "Error";
                return(View());
            }
        }
        private bool IsValid(string usernam, string password)
        {
            var  crypto  = new SimpleCrypto.PBKDF2();
            bool IsValid = false;

            using (var db = new paresetEntities())
            {
                var user = db.Userinfoes.FirstOrDefault(u => u.username == usernam);


                if (user != null)
                {
                    if (user.password == crypto.Compute(password, user.passwordsalt))
                    {
                        return(true);
                    }
                }
                int count = int.Parse(user.failurecount.ToString());

                user.failurecount = count + 1;
                db.Entry(user).CurrentValues.SetValues(user);
                db.SaveChanges();
            }

            return(IsValid);
        }
Esempio n. 3
0
        public ActionResult configauthoptions(checkboxforauthoptions confauthoptionsobj)
        {
            try
            {
                paresetEntities db = new paresetEntities();

                var obj = db.Userauthoptions.ToList();
                obj[0].Isenabel = confauthoptionsobj.Email;
                obj[1].Isenabel = confauthoptionsobj.smsotp;
                obj[2].Isenabel = confauthoptionsobj.challengeqs;

                //obj.Emailotp = confauthoptionsobj.emailotp;
                //obj.Charesq = confauthoptionsobj.challengequestions;
                //obj.Smsotp = confauthoptionsobj.smsotp;
                foreach (var m in obj)
                {
                    db.Entry(m).CurrentValues.SetValues(m);
                    db.SaveChanges();
                }

                ModelState.Clear();
                ViewBag.Message = "Success";
                return(View(confauthoptionsobj));
            }

            catch
            {
                ViewBag.Message = "Error";
                return(View());
            }
        }
Esempio n. 4
0
        public ActionResult Myprofile(UserReg user)
        {
            paresetEntities db  = new paresetEntities();
            var             obj = db.Userinfoes.Where(c => c.username == user.Username).First();

            try
            {
                obj.username = user.Username;
                obj.email    = user.email;
                //obj.adminq = user.Adinq;
                obj.ansforaq = user.Ansforaq;
                obj.userq    = user.Userq;
                obj.ansforuq = user.Ansforuq;
                obj.phone    = user.phone;
                //user.password = obj.password;
                //  user.Userq = (int)obj.userq;
                db.Entry(obj).CurrentValues.SetValues(obj);
                db.SaveChanges();
                ModelState.Clear();
                ViewBag.Message = "Success";
            }
            catch (Exception cex)
            {
                ViewBag.Message = "Error";
            }
            return(View(GetusqlistA()));
        }
        public ActionResult Signup(UserReg user)
        {
            if (user.Username != null && user.Password != null && user.email != null && user.Ansforaq != null && user.Ansforuq != null && user.ConfirmPassword != null)
            {
                //if (DoesUserExist(user.Username))
                //{
                using (paresetEntities dc = new paresetEntities())
                {
                    //you should check duplicate registration here
                    var           adminq    = dc.Admininfoes.FirstOrDefault(u => u.aid == 1);
                    List <string> lstResult = (from table in dc.Userinfoes
                                               where table.username == user.Username
                                               select table.password).ToList();
                    if (lstResult.Count == 0)
                    {
                        Userinfo u          = new Userinfo();
                        var      crypto     = new SimpleCrypto.PBKDF2();
                        var      encrypPass = crypto.Compute(user.Password);
                        u.username      = user.Username;
                        u.password      = encrypPass;
                        u.passwordsalt  = crypto.Salt;
                        u.email         = user.email;
                        u.phone         = user.phone;
                        u.adminq        = adminq.adminsq;
                        u.ansforaq      = user.Ansforaq;
                        u.userq         = user.Userq;
                        u.ansforuq      = user.Ansforuq;
                        u.AdminApproved = true;
                        u.failurecount  = 0;
                        dc.Userinfoes.Add(u);
                        dc.SaveChanges();
                        // ModelState.Clear();
                        user            = null;
                        ViewBag.Message = "Success";
                    }
                    else
                    {
                        ViewBag.Message = "Error2";
                    }
                }
                //}
                //else
                //{
                //    ViewBag.Message = "Invalid user name.";
                //}
            }
            else
            {
                ViewBag.Message = "Error1";
            }

            return(View(Getusqlist()));
        }
Esempio n. 6
0
        public ActionResult adminview(Admindetails Admind, String Command)
        {
            if (Command == "Update")
            {
                if (Admind.serveradminname != null && Admind.serveradminpass != null && Admind.DomainName != null && Admind.DomainIP != null)
                {
                    IPAddress ip;
                    bool      ValidateIP = IPAddress.TryParse(Admind.DomainIP, out ip);

                    if (ValidateIP)
                    {
                        paresetEntities db  = new paresetEntities();
                        var             obj = db.Admininfoes.Where(c => c.adminname == User.Identity.Name).First();
                        obj.serveradminname = Admind.serveradminname;
                        obj.serveradminpass = Admind.serveradminpass;
                        // obj.adminsq = Admind.AdminSq;
                        obj.dmainname = Admind.DomainName;
                        obj.domainip  = Admind.DomainIP;

                        db.Entry(obj).CurrentValues.SetValues(obj);
                        db.SaveChanges();
                        //ModelState.Clear();
                        ViewBag.Message = "Success1";
                    }
                }
            }
            else
            {
                try
                {
                    DirectoryEntry entry        = new DirectoryEntry("LDAP://" + Admind.DomainIP, Admind.serveradminname, Admind.serveradminpass);
                    object         nativeObject = entry.NativeObject;
                    ViewBag.Message = "Success2";
                }
                catch (DirectoryServicesCOMException cex)
                {
                    //not authenticated; reason why is in cex
                    ViewBag.Message = "Error";
                }
                catch (Exception ex)
                {
                    //not authenticated due to some other exception [this is optional]
                    ViewBag.Message = "Error";
                }
            }
            //Admindetails objcountrymodel1 = new Admindetails();
            //objcountrymodel1.Adminsqlist = GetAsqlist();
            //return View(objcountrymodel1);
            return(View());
        }
        public static void WorkThreadFunction(object importcsv)
        {
            paresetEntities dc        = new paresetEntities();
            List <string>   csvvalue1 = loadCsvFile(importcsv.ToString());

            string[] _values = null;
            failedrcrd = 0;
            threadstop = false;
            foreach (string obj in csvvalue1)
            {
                if (threadstop == true)
                {
                    break;
                }
                _values = obj.Split(',');

                // var user = dc.Userinfoes.FirstOrDefault(m => m.username == _values[0].ToString());
                string        name      = _values[0].ToString();
                List <string> lstResult = (from table in dc.Userinfoes
                                           where table.username == name
                                           select table.password).ToList();
                if (lstResult.Count == 0)
                {
                    Userinfo u          = new Userinfo();
                    var      crypto     = new SimpleCrypto.PBKDF2();
                    var      encrypPass = crypto.Compute(_values[1]);
                    u.username      = _values[0];
                    u.password      = encrypPass;
                    u.passwordsalt  = crypto.Salt;
                    u.email         = _values[2];
                    u.phone         = _values[3];
                    u.adminq        = int.Parse(_values[4].ToString());
                    u.ansforaq      = _values[5];
                    u.userq         = int.Parse(_values[6].ToString());
                    u.ansforuq      = _values[7];
                    u.AdminApproved = true;
                    dc.Userinfoes.Add(u);
                    dc.SaveChanges();
                    successrcrd = successrcrd + 1;
                }
                else
                {
                    failedrcrd = failedrcrd + 1;
                }
                cssrecords = cssrecords - 1;
            }
        }
Esempio n. 8
0
 public ActionResult EnableUser(Enableusr enable)
 {
     try
     {
         paresetEntities db  = new paresetEntities();
         var             obj = db.Userinfoes.Where(c => c.username == enable.username).First();
         obj.failurecount  = 0;
         obj.AdminApproved = true;
         db.Entry(obj).CurrentValues.SetValues(obj);
         db.SaveChanges();
         ViewBag.Message = "Success1";
     }
     catch (Exception cex)
     {
         ViewBag.Message = "Error";
     }
     return(View());
 }
Esempio n. 9
0
        public ActionResult SelectAdmiqforuser(Admindetails admind)
        {
            paresetEntities db  = new paresetEntities();
            var             obj = db.Admininfoes.Where(c => c.adminname == User.Identity.Name).First();

            obj.adminsq = admind.AdminSq;


            db.Entry(obj).CurrentValues.SetValues(obj);
            db.SaveChanges();
            ModelState.Clear();
            ViewBag.Message = "Success";
            Admindetails objcountrymodel1 = new Admindetails();

            objcountrymodel1.Adminsqlist = GetAsqlist();
            var Aq1 = db.Chresqlists.FirstOrDefault(u => u.id == admind.AdminSq);

            objcountrymodel1.AdminSqaslbl = Aq1.Adminsqlist.ToString();

            return(View(objcountrymodel1));
        }
Esempio n. 10
0
        public ActionResult changeuserpass(Passwordchange A)
        {
            // var crypto = new SimpleCrypto.PBKDF2();


            using (var db = new paresetEntities())
            {
                if (A.ChangePassword == A.ConfirmPassword)
                {
                    var user = db.Userinfoes.FirstOrDefault(u => u.username == A.Username);



                    if (user != null)
                    {
                        var crypto     = new SimpleCrypto.PBKDF2();
                        var encrypPass = crypto.Compute(A.ChangePassword);
                        user.password     = encrypPass;
                        user.passwordsalt = crypto.Salt;
                        db.Entry(user).CurrentValues.SetValues(A);
                        db.SaveChanges();
                        ModelState.Clear();
                        ViewBag.Message = "Success";
                    }
                    else
                    {
                        ViewBag.Message = "Error1";
                    }
                }
                else
                {
                    ViewBag.Message = "Error2";
                }
            }
            return(View());
        }
Esempio n. 11
0
        public ActionResult UpdateusersfromAD(string ad)
        {
            // List<Users> lstADUsers = new List<Users>();
            paresetEntities dc     = new paresetEntities();
            var             admind = dc.Admininfoes.FirstOrDefault(u => u.adminname == User.Identity.Name);
            //var name = from i in dc.Admininfoes
            //           where i.adminname == User.Identity.Name
            //           select i.domainip;

            //var name1 = from i in dc.Admininfoes
            //           where i.adminname == User.Identity.Name
            //           select i.adminpass;

            // string DomainPath = "LDAP://192.168.10.11";
            string DomainPath = "LDAP://" + admind.domainip;

            string adminpassw = admind.adminpass;

            try
            {
                DirectoryEntry    searchRoot = new DirectoryEntry(DomainPath, User.Identity.Name, adminpassw);
                DirectorySearcher search     = new DirectorySearcher(searchRoot);

                // search.Filter = "(&(objectClass=user)(objectCategory=person))";
                search.Filter = "(&(objectClass=person)(objectCategory=user))";
                //search.Filter = "(&(objectClass=Users))";
                search.PropertiesToLoad.Add("sAMAccountname");
                search.PropertiesToLoad.Add("mail");
                search.PropertiesToLoad.Add("usergroup");
                search.PropertiesToLoad.Add("name");//first name
                SearchResult           result;
                SearchResultCollection resultCol = search.FindAll();
                if (resultCol != null)
                {
                    for (int counter = 0; counter < resultCol.Count; counter++)
                    {
                        string UserNameEmailString = string.Empty;
                        result = resultCol[counter];
                        if (result.Properties.Contains("sAMAccountname") &&
                            result.Properties.Contains("mail") &&
                            result.Properties.Contains("name"))
                        {
                            UsersinAD objSurveyUsers = new UsersinAD();
                            objSurveyUsers.Email = (String)result.Properties["mail"][0];

                            objSurveyUsers.UserName    = (String)result.Properties["samaccountname"][0];
                            objSurveyUsers.DisplayName = (String)result.Properties["name"][0];
                            // objSurveyUsers.Isregistered = 0;
                            //you should check duplicate registration here
                            List <string> lstResult = (from table in dc.UsersinADs
                                                       where table.UserName == objSurveyUsers.UserName
                                                       select table.UserName).ToList();
                            if (lstResult.Count == 0)
                            {
                                dc.UsersinADs.Add(objSurveyUsers);
                                dc.SaveChanges();
                            }
                        }
                    }
                    ViewBag.Message = "Success";
                }
            }
            catch (DirectoryServicesCOMException cex)
            {
                //not authenticated; reason why is in cex
                ViewBag.Message = "Error";
            }
            catch (Exception ex)
            {
                //not authenticated due to some other exception [this is optional]
                ViewBag.Message = "Error";
            }

            return(View());
        }
Esempio n. 12
0
        public ActionResult Setpassword(Account set, String Command)
        {
            if (Command == "ResetPassword")
            {
                if ((0 == String.Compare(set.password, set.Confirmpassword, true)))
                {
                    string          username = User.Identity.Name;
                    paresetEntities dc       = new paresetEntities();

                    var admind = dc.Admininfoes.FirstOrDefault(u => u.aid == 1);

                    string adminUser     = admind.adminname;
                    string adminPassword = admind.adminpass;
                    string fullPath      = "LDAP://" + admind.domainip;
                    try
                    {
                        DirectoryEntry entry = new DirectoryEntry(fullPath, adminUser, adminPassword);
                        //var directoryEntry = GetDirectoryEntryByUserName(username);
                        DirectorySearcher dirSearcher = new DirectorySearcher(entry);
                        string            filter      = string.Format("(SAMAccountName={0})", username);
                        dirSearcher.Filter = filter;
                        SearchResult result = dirSearcher.FindOne();
                        if (result != null)
                        {
                            DirectoryEntry userEntry = result.GetDirectoryEntry();

                            //Enable Account if it is disabled
                            userEntry.Properties["userAccountControl"].Value = 0x200;
                            //Reset User Password
                            userEntry.Invoke("SetPassword", new object[] { set.password });
                            //Force user to change password at next logon
                            //userEntry.Properties["pwdlastset"][0] = 1; ////////////to be modified
                            userEntry.CommitChanges();
                            userEntry.Close();
                        }

                        useraudit obj = new useraudit();
                        obj.UserName = username;
                        string ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString();
                        obj.ipaddress = ip;
                        DateTime now = DateTime.Now.ToLocalTime();
                        obj.paswordchangedate = now;
                        dc.useraudits.Add(obj);
                        dc.SaveChanges();



                        ViewBag.Message = "Success";
                    }



                    catch (Exception ex)
                    {
                        if (ex.HResult == -2146232828)
                        {
                            ViewBag.Message = "Error3";
                        }
                        else
                        {
                            //not authenticated due to some other exception [this is optional]
                            ViewBag.Message = "Error2";
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Error1";
                }
                paresetEntities dc1  = new paresetEntities();
                Account         obj1 = new Account();
                obj1.username = User.Identity.Name.ToString();
                obj1.plist    = dc1.Pwdpolicies.ToList();
                return(View(obj1));
            }
            else
            {
                FormsAuthentication.SignOut();
                return(RedirectToAction("Login", "Home"));
            }
        }