Ejemplo n.º 1
0
        public bool sendSMSDetails(string username)
        {
            try
            {
                //generate random string
                string        otpstr   = RandomString(6);
                SMSRequest    smsObj   = new SMSRequest();
                DatabaseLayer dbObj    = new DatabaseLayer();
                string        mobileno = getuserMobileNo(username);
                SSAErrorLog   logObj   = new SSAErrorLog();

                if (mobileno != null)
                {
                    string query = "delete from userotp where username='******'";
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "query delete " + query);
                    dbObj.deleteTableData(query);

                    string str = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
                    dbObj.insertTableData("insert into userotp (username,otp,otpcreatedatetime,otpactivate) values ('" + QASecurity.Encryptdata(username) + "','" + otpstr + "','" + String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + "' , 0) ");
                    //insert into db
                    //send SMS
                    smsObj.sendSMS(mobileno, ConfigurationManager.AppSettings["otpmessage"].ToString() + " " + otpstr);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception er)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static DirectoryEntry GetDirectoryEntryByUserName(string userName)
        {
            //  var de = GetDirectoryObj();// (GetDomain());
            SSAErrorLog logObj = new SSAErrorLog();

            try
            {
                string domain = ConfigurationManager.AppSettings["domain"];
                var    de     = GetDirectoryObject(domain);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObject1   " + de.Name);


                var search = new DirectorySearcher(de);// { SearchRoot = de, Filter = "(&(objectCategory=user)(cn=" + userName + "))" };

                search.Filter = "(SAMAccountName=" + userName + ")";

                search.PropertiesToLoad.Add("cn");

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObject2   ");

                //SearchResult result = search.FindOne();


                var results = search.FindOne();

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObject3   " + results.Properties.Count);

                return(results != null?results.GetDirectoryEntry() : null);
            }
            catch (Exception er)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObject4   " + er.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public Hashtable getuserDetails(string userid)
        {
            Hashtable   getData  = null;
            string      mobileno = null;
            SSAErrorLog logObj   = new SSAErrorLog();

            try
            {
                string domainName = ConfigurationManager.AppSettings["domain"];
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "getAccountDetailsuserid 1" + userid);
                getData = IsAuthenticateduserinfo(domainName, userid, "");
                //DateTime.FromFileTime((long)searchResult.Properties["lastLogon"][0]);
                //displayuser.Text = getData["principalname"].ToString();
                //username.Text = getData["principalname"].ToString(); //Session["username"].ToString();

                //lastlogon.Text = getData["lastlogontimestamp"].ToString();
                //pwdstatus.Text = getData["passwordexpired"].ToString();
                //pwdlastchange.Text = getData["pwdlastchanged"].ToString();
                ////passwordexpire.Text = getData["passwordexpires"].ToString();
                //accountcreated.Text = getData["whencreated"].ToString();
                //activestatus.Text = getData["lockouttime"].ToString();
                //HiddenField1.Value = getData["emailid"].ToString();

                mobileno = getData["mobileno"].ToString();
            }
            catch (Exception er)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "getAccountDetails" + er.Message);
            }

            return(getData);
        }
Ejemplo n.º 4
0
        protected void getAccountDetails()
        {
            Hashtable   getData = null;
            string      userid  = "";
            SSAErrorLog logObj  = new SSAErrorLog();

            try
            {
                if (Session["userid"] != null)
                {
                    userid = Session["userid"].ToString();
                }
                else if (Session["forgetpwduser"] != null)
                {
                    userid = Session["forgetpwduser"].ToString();
                }
                else
                {
                    Response.Redirect("SelfServiceLogin.aspx");
                }

                string domainName = ConfigurationManager.AppSettings["domain"];
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "getAccountDetailsuserid 1" + userid);
                getData = IsAuthenticateduserinfo(domainName, userid, "");
                //DateTime.FromFileTime((long)searchResult.Properties["lastLogon"][0]);
                displayuser.Text = getData["principalname"].ToString();
                username.Text    = getData["principalname"].ToString(); //Session["username"].ToString();

                //lastlogon.Text = getData["lastlogontimestamp"].ToString();
                // pwdstatus.Text = getData["passwordexpired"].ToString();
                //pwdlastchange.Text = getData["pwdlastchanged"].ToString();
                //passwordexpire.Text = getData["passwordexpires"].ToString();
                // accountcreated.Text = getData["whencreated"].ToString();
                // activestatus.Text = getData["lockouttime"].ToString();
                //mobileno.Text = getData["mobile"].ToString();
                if (getData["mobile"] != null)
                {
                    string mobilestr = getData["mobile"].ToString();
                    //mobilestr = mobilestr.Substring(0, mobilestr.Length - 4) + "XXXX";
                    //mobilestr = mobilestr.Substring(0, mobilestr.Length - 4) + "XXXX";
                    mobilestr     = "XX XX XX" + mobilestr.Substring(mobilestr.Length - 4);
                    mobileno.Text = mobilestr;
                }
                else
                {
                    mobileno.Text = "Mobile Number not available/configured, Please contact Administrator";
                }

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get mail details . .." + getData["emailid"].ToString());
                HiddenField1.Value = getData["mail"].ToString();
            }
            catch (Exception er)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "getAccountDetails" + er.Message);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //mp1.Hide();

            try
            {
                SSAErrorLog        logObj     = new SSAErrorLog();
                LdapAuthentication ldapObj    = new LdapAuthentication();
                string             domainName = ConfigurationManager.AppSettings["domain"];
                string             displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, Session["pwd"].ToString());
                DatabaseLayer      dataObj    = new DatabaseLayer();


                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal  " + displayVal);


                if (displayVal != null)
                {
                    Session["username"] = displayVal;

                    string userid = userNameTxt.Text.ToLower();
                    Session["pwd"]    = passwordTxt.Text;
                    Session["userid"] = userid;

                    // DatabaseLayer dataObj = new DatabaseLayer();
                    if (dataObj.getTablerowCount("userquestionanswers", "username='******'"))
                    {
                        Session["update"] = "yes";
                    }
                    else
                    {
                        Session["update"] = "no";
                    }

                    // Server.Transfer("SSAHome.aspx",true);
                    //update session object..
                    string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'";
                    dataObj.insertTableData(updateStr);
                    Response.Redirect("SSAHome.aspx", false);
                }
                else
                {
                    Errorlabel.Text = "Authentication Failed !!!";
                    Session.RemoveAll();
                }
            }
            catch (Exception er)
            {
                Errorlabel.Text = "Authentication Failed !!!";
            }
        }
Ejemplo n.º 6
0
        public static DirectoryEntry GetDirectoryObj()
        {
            SSAErrorLog logObj = new SSAErrorLog();

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj1");

            string username = ConfigurationManager.AppSettings["adminuser"];  //WebConfigurationManager.AppSettings["adAdminUser"];
            string pwd      = ConfigurationManager.AppSettings["adminpwd"];
            string domain   = ConfigurationManager.AppSettings["domain"];

            string domainAndUsername = domain + @"\" + username;

            DirectoryEntry entry = new DirectoryEntry("", domainAndUsername, pwd);

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj12" + entry);
            DirectoryEntry userentry = null;


            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj121" + obj);
                DirectorySearcher search = new DirectorySearcher(entry);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj122 " + search.Filter);
                search.Filter = "(SAMAccountName=" + username + ")";
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj123 " + search.Filter);
                search.PropertiesToLoad.Add("cn");
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj124 " + search.Filter);
                SearchResult result = search.FindOne();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj125 " + result);
                userentry = result.GetDirectoryEntry();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj126 " + userentry.Name);
                if (null == result)
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj127 null ");
                    return(null);
                }
                else
                {
                    userentry.Close();
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj128 " + userentry);
                    return(userentry);
                }
            }
            catch (Exception ex)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "GetDirectoryObj  " + ex.Message);
                throw new Exception("Error authenticating user. " + ex.Message);
            }
        }
Ejemplo n.º 7
0
        protected bool  ResetUserPassword(string usernametxt)
        {
            SSAErrorLog logObj = new SSAErrorLog();

            try
            {
                var userDn = "";
                var pwd    = TextBox1.Text;
                if (Session["userid"] != null)
                {
                    userDn = Session["userid"].ToString();
                }
                else
                {
                    userDn = Session["forgetpwduser"].ToString();
                }

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "userDn   >> " + userDn);
                var directoryEntry = GetDirectoryEntryByUserName(userDn);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "userDn 2  >> " + userDn);
                directoryEntry.Invoke("SetPassword", new object[] { pwd });
                directoryEntry.CommitChanges();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "userDn  3 >> " + userDn);
                directoryEntry.Properties["LockOutTime"].Value = 0;
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "userDn  4 >> " + userDn);
                directoryEntry.CommitChanges();
                directoryEntry.Close();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "userDn  5 >> " + userDn);
                //send email here..
                SSAEmail emailObj  = new SSAEmail();
                string   portnostr = ConfigurationManager.AppSettings["port"].ToString();
                int      portNum   = Int32.Parse(portnostr);
                string   msg       = ConfigurationManager.AppSettings["emailmsg"].ToString();
                string   username  = usernametxt;
                string   emailMsg  = string.Format(msg, username);
                emailObj.sendEmail(HiddenField1.Value, "Password Reset Sucessful", emailMsg, ConfigurationManager.AppSettings["emailusername"].ToString(), ConfigurationManager.AppSettings["emailpwd"].ToString(), ConfigurationManager.AppSettings["serverip"].ToString(), portNum, ConfigurationManager.AppSettings["fromemailid"].ToString());


                return(true);
            }
            catch (Exception er)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Exception in ResetUserPwd  " + er.Message + "Source  " + er.Source + "excep " + er.StackTrace + " inner exceptionnn  " + er.InnerException.Message);
                return(false);
            }
        }
Ejemplo n.º 8
0
        protected void continue_Click(object sender, EventArgs e)
        {
            mp1.Hide();
            SSAErrorLog logObj = new SSAErrorLog();

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), " oneee loginid.session..  " + Session["forgetpwduser"]);
            DatabaseLayer dataObj = new DatabaseLayer();

            if (getUserQAs(Session["forgetpwduser"].ToString().ToLower()))
            {
                string updateStr = "update usersession set sessionobj='" + Session["__AntiXsrfToken"] + "' where userid='" + Session["forgetpwduser"].ToString() + "'";
                dataObj.insertTableData(updateStr);
                Session["nocheck"] = "yes";
                Response.Redirect("RestPasswordQA.aspx");
            }
            else
            {
                Session["nocheck"] = null;
                Errorlbl.Text      = "You have not registered on the portal. Please contact local MSOLVE team to get your password reset." + "<br />" + " Please register yourself for self service portal use";
                Errorlbl.ForeColor = Color.Red;
                return;
            }
        }
Ejemplo n.º 9
0
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes"))
                {
                    if (this.txtimgcode.Text == this.Session["CaptchaImageText"].ToString())
                    {
                        //lblmsg.Text = "Excellent.......";
                    }
                    else
                    {
                        lblmsg.Text = "Please Enter valid Captcha.";
                        return;
                    }
                    this.txtimgcode.Text = "";
                }

                if (ResetUserPassword(username.Text))
                {
                    Response.Redirect("ResetSucess.aspx", false);
                }
                else
                {
                    Response.Redirect("AuthFailed.aspx", false);
                }
                Session.RemoveAll();
            }
            catch (Exception er)
            {
                SSAErrorLog logObj = new SSAErrorLog();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), er.Message);
                Session.RemoveAll();
                Response.Redirect("AuthFailed.aspx", false);
            }
        }
Ejemplo n.º 10
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DatabaseLayer dataObj = new DatabaseLayer();
            SSAErrorLog   logObj  = new SSAErrorLog();

            if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes"))
            {
                if (this.txtimgcode.Text == this.Session["CaptchaImageText"].ToString())
                {
                    //lblmsg.Text = "Excellent.......";
                }
                else
                {
                    lblmsg.Text = "Please Enter valid Captcha.";
                    return;
                }
                this.txtimgcode.Text = "";
            }



            if (txtloginid.Text == "")
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text      = "Please enter valid Login ID!!";
            }
            else
            {
                //here is what we need to check whether user logged in or not
                string str = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
                if (!dataObj.getTablerowCount("usersession", "userid='" + txtloginid.Text + "'"))
                {
                    ArrayList userArray1 = new ArrayList();
                    userArray1.Add("userid");
                    userArray1.Add("sessionobj");
                    userArray1.Add("createddate");
                    userArray1.Add("logincounter");



                    ArrayList userArray     = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + txtloginid.Text.ToLower() + "'", "idusersession", userArray1);
                    int       counter       = (int)Convert.ToInt64(userArray[3].ToString());
                    DateTime  createDate    = Convert.ToDateTime(userArray[2].ToString());
                    DateTime  currentDate   = DateTime.Now;
                    int       configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString());
                    int       sessionLock   = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString());
                    string    err           = ConfigurationManager.AppSettings["sessionlockmsg"].ToString();

                    if (((currentDate - createDate).Minutes <= sessionLock) && (counter >= configCounter))
                    {
                        int    diffDate      = (currentDate - createDate).Minutes;
                        int    remainingTime = sessionLock - diffDate;
                        string errorMsg      = string.Format(err, remainingTime);
                        Errorlbl.Text = errorMsg; //"Please try after some time, User is locked due to no of tries are exceeded..";
                                                  //Response.Redirect("SSAHome.aspx");
                                                  // Session.RemoveAll();
                        return;
                    }

                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), " Now rows.. insert ...  ");
                    dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + txtloginid.Text + "','" + Session["__AntiXsrfToken"] + "','" + str + "',0)");
                    if (getUserQAs(txtloginid.Text.ToLower()))
                    {
                        Session["forgetpwduser"] = txtloginid.Text.ToLower();
                        Response.Redirect("RestPasswordQA.aspx");
                    }

                    else
                    {
                        Errorlbl.Text      = "You have not registered on the portal. Please contact local MSOLVE team to get your password reset." + "<br />" + " Please register yourself for self service portal use";
                        Errorlbl.ForeColor = Color.Red;
                        return;
                    }
                }
                else
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), " are we hereee???...  ");
                    Session["forgetpwduser"] = txtloginid.Text.ToLower();
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), " oneee loginid???...  " + txtloginid.Text.ToLower());



                    ArrayList userArray1 = new ArrayList();
                    userArray1.Add("userid");
                    userArray1.Add("sessionobj");
                    userArray1.Add("createddate");
                    userArray1.Add("logincounter");



                    ArrayList userArray     = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + txtloginid.Text.ToLower() + "'", "idusersession", userArray1);
                    int       counter       = (int)Convert.ToInt64(userArray[3].ToString());
                    DateTime  createDate    = Convert.ToDateTime(userArray[2].ToString());
                    DateTime  currentDate   = DateTime.Now;
                    int       configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString());
                    int       sessionLock   = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString());
                    string    err           = ConfigurationManager.AppSettings["sessionlockmsg"].ToString();

                    if (((currentDate - createDate).Minutes <= sessionLock) && (counter >= configCounter))
                    {
                        int    diffDate      = (currentDate - createDate).Minutes;
                        int    remainingTime = sessionLock - diffDate;
                        string errorMsg      = string.Format(err, remainingTime);
                        Errorlbl.Text = errorMsg; //"Please try after some time, User is locked due to no of tries are exceeded..";
                                                  //Response.Redirect("SSAHome.aspx");
                                                  // Session.RemoveAll();
                        return;
                    }
                    else
                    {
                        mp1.Show();
                        return;
                    }
                    //mp1.Show();
                    //return;
                }
            }
        }
        protected void Login_Click(object sender, EventArgs e)
        {
            DatabaseLayer dataObj = new DatabaseLayer();
            SSAErrorLog   logObj  = new SSAErrorLog();

            try
            {
                if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes"))
                {
                    if (txtimgcode.Text == Session["CaptchaImageText"].ToString())
                    {
                        //lblmsg.Text = "Excellent.......";
                    }
                    else
                    {
                        lblmsg.Text = "Please Enter valid Captcha.";
                        return;
                    }
                    this.txtimgcode.Text = "";
                }

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Loggedin");

                LdapAuthentication ldapObj    = new LdapAuthentication();
                string             domainName = ConfigurationManager.AppSettings["domain"];

                string str = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                if (dataObj.getTablerowCount("usersession", "userid='" + userNameTxt.Text + "'"))
                {
                    ArrayList userArray1 = new ArrayList();

                    userArray1.Add("userid");
                    userArray1.Add("sessionobj");
                    userArray1.Add("createddate");
                    userArray1.Add("logincounter");
                    ArrayList userArray = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + userNameTxt.Text + "'", "idusersession", userArray1);
                    int       counter   = (int)Convert.ToInt64(userArray[3].ToString());
                    //DateTime createDate = (DateTime) userArray[2];
                    DateTime createDate    = Convert.ToDateTime(userArray[2].ToString());
                    DateTime currentDate   = DateTime.Now;
                    int      configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString());
                    int      sessionLock   = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString());


                    string err = ConfigurationManager.AppSettings["sessionlockmsg"].ToString();

                    if (((currentDate - createDate).Minutes <= sessionLock) && (counter >= configCounter))
                    {
                        int    diffDate      = (currentDate - createDate).Minutes;
                        int    remainingTime = sessionLock - diffDate;
                        string errorMsg      = string.Format(err, remainingTime);
                        Errorlabel.Text = errorMsg; //"Please try after some time, User is locked due to no of tries are exceeded..";
                                                    //Response.Redirect("SSAHome.aspx");
                                                    // Session.RemoveAll();
                        return;
                    }

                    //Session[AntiXsrfTokenKey]
                    //userid,sessionobj,createddate

                    string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'";

                    //dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)");
                    dataObj.insertTableData(updateStr);


                    //dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)" )                   ;

                    string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text);



                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal  " + displayVal);

                    //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal);
                    //userNameTxt.Text = "done ";
                    //Session["username"] = userNameTxt.Text;
                    if (displayVal != null)
                    {
                        //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal);
                        Session["username"] = displayVal;

                        string userid = userNameTxt.Text.ToLower();
                        Session["pwd"]    = passwordTxt.Text;
                        Session["userid"] = userid;

                        // DatabaseLayer dataObj = new DatabaseLayer();
                        if (dataObj.getTablerowCount("userquestionanswers", "username='******'"))
                        {
                            Session["update"] = "yes";
                        }
                        else
                        {
                            Session["update"] = "no";
                        }


                        Response.Redirect("SSAHome.aspx", false);
                    }
                    else
                    {
                        //userNameTxt.Text = "err";
                        Errorlabel.Text = "Authentication Failed !!!";
                        //Response.Redirect("SSAHome.aspx");
                        Session.RemoveAll();
                    }
                }
                else
                {
                    Hashtable userHash   = new Hashtable();
                    ArrayList userArray1 = new ArrayList();
                    userArray1.Add("userid");
                    userArray1.Add("sessionobj");
                    userArray1.Add("createddate");
                    userArray1.Add("logincounter");

                    //check the session here..
                    //userHash = dataObj.getTableData("usersession", userArray, "idusersession", "userid='" + userNameTxt.Text + "'");
                    //  ArrayList dataValues = dataObj.getTableDataQuery("", "userid='" + userNameTxt.Text + "'", "idusersession", userArray);
                    //get confirmation from request, If confirmed then login and update the session,
                    //else terminate this request.


                    // dialog.Visible = true;
                    Session["pwd"] = passwordTxt.Text;

                    // ArrayList userArray = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + userNameTxt.Text + "'", "idusersession", userArray1);
                    //  int counter = (int)Convert.ToInt64(userArray[3].ToString());
                    // DateTime createDate = Convert.ToDateTime(userArray[2].ToString());
                    //  DateTime currentDate = DateTime.Now;
                    int    configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString());
                    int    sessionLock   = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString());
                    string err           = ConfigurationManager.AppSettings["sessionlockmsg"].ToString();

                    //LdapAuthentication ldapObj = new LdapAuthentication();
                    //string domainName = ConfigurationManager.AppSettings["domain"];
                    //string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, Session["pwd"].ToString());
                    string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text);
                    if (displayVal != null)
                    {
                        Session["username"] = displayVal;

                        string userid = userNameTxt.Text.ToLower();
                        Session["pwd"]    = passwordTxt.Text;
                        Session["userid"] = userid;

                        // DatabaseLayer dataObj = new DatabaseLayer();
                        if (dataObj.getTablerowCount("userquestionanswers", "username='******'"))
                        {
                            Session["update"] = "yes";
                        }
                        else
                        {
                            Session["update"] = "no";
                        }

                        // Server.Transfer("SSAHome.aspx",true);
                        //update session object..
                        //string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'";

                        dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)");
                        //dataObj.insertTableData(updateStr);
                        Response.Redirect("SSAHome.aspx", false);
                    }
                    else
                    {
                        Errorlabel.Text = "Authentication Failed !!!";
                        Session.RemoveAll();
                    }



                    /*
                     * if (((currentDate- createDate).Minutes <= sessionLock) && (counter >= configCounter))
                     * {
                     *  int diffDate = (currentDate - createDate).Minutes;
                     *  int remainingTime = sessionLock - diffDate;
                     *  string errorMsg = string.Format(err, remainingTime);
                     *  Errorlabel.Text = errorMsg;//"Please try after some time, User is locked due to no of tries are exceeded..";
                     *  //Response.Redirect("SSAHome.aspx");
                     * // Session.RemoveAll();
                     *  return;
                     * }
                     * else
                     * {
                     * // mp1.Show();
                     *  return;
                     * }
                     */


                    // userHash[]
                }


                /*
                 *
                 * string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text);
                 *
                 *
                 *
                 * logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal  " + displayVal);
                 *
                 * //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal);
                 * //userNameTxt.Text = "done ";
                 * //Session["username"] = userNameTxt.Text;
                 * if (displayVal != null)
                 * {
                 * //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal);
                 * Session["username"] = displayVal;
                 *
                 * string userid = userNameTxt.Text.ToLower();
                 * Session["pwd"] = passwordTxt.Text;
                 * Session["userid"] = userid;
                 *
                 * // DatabaseLayer dataObj = new DatabaseLayer();
                 * if (dataObj.getTablerowCount("userquestionanswers", "username='******'"))
                 * {
                 *     Session["update"] = "yes";
                 * }
                 * else
                 * {
                 *     Session["update"] = "no";
                 * }
                 *
                 * // Server.Transfer("SSAHome.aspx",true);
                 * Response.Redirect("SSAHome.aspx",false);
                 *
                 * }
                 * else
                 * {
                 * //userNameTxt.Text = "err";
                 * Errorlabel.Text = "Authentication Failed !!!";
                 * //Response.Redirect("SSAHome.aspx");
                 * Session.RemoveAll();
                 * }
                 */
            }
            catch (Exception er)
            {
                //userNameTxt.Text = "err";
                //  System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login3.txt", "displayVal " + er.Message + "  StackTrace  " + er.StackTrace);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Error While authenticating   " + er.Message);
                Errorlabel.Text = "Authentication Failed !!!";
                //Session.RemoveAll();
            }
        }
Ejemplo n.º 12
0
        protected void Login_Click(object sender, EventArgs e)
        {
            try
            {
                if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes"))
                {
                    if (txtimgcode.Text == Session["CaptchaImageText"].ToString())
                    {
                        //lblmsg.Text = "Excellent.......";
                    }
                    else
                    {
                        lblmsg.Text = "Please Enter valid Captcha.";
                        return;
                    }
                    this.txtimgcode.Text = "";
                }
                SSAErrorLog logObj = new SSAErrorLog();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Loggedin");

                LdapAuthentication ldapObj    = new LdapAuthentication();
                string             domainName = ConfigurationManager.AppSettings["domain"];
                string             displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal  " + displayVal);

                //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal);
                //userNameTxt.Text = "done ";
                //Session["username"] = userNameTxt.Text;
                if (displayVal != null)
                {
                    //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal);
                    Session["username"] = displayVal;

                    string userid = userNameTxt.Text.ToLower();
                    Session["pwd"]    = passwordTxt.Text;
                    Session["userid"] = userid;

                    DatabaseLayer dataObj = new DatabaseLayer();
                    if (dataObj.getTablerowCount("userquestionanswers", "username='******'"))
                    {
                        Session["update"] = "yes";
                    }
                    else
                    {
                        Session["update"] = "no";
                    }

                    // Server.Transfer("SSAHome.aspx",true);
                    Response.Redirect("SSAHome.aspx", false);
                }
                else
                {
                    //userNameTxt.Text = "err";
                    Errorlabel.Text = "Authentication Failed !!!";
                    //Response.Redirect("SSAHome.aspx");
                    Session.RemoveAll();
                }
            }
            catch (Exception er)
            {
                //userNameTxt.Text = "err";
                //  System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login3.txt", "displayVal " + er.Message + "  StackTrace  " + er.StackTrace);
                Errorlabel.Text = "Authentication Failed !!!";
                //Session.RemoveAll();
            }
        }
Ejemplo n.º 13
0
        public Hashtable IsAuthenticateduserinfo(string domain, string username, string pwd)
        {
            SSAErrorLog logObj = new SSAErrorLog();

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfoe1");
            string         domainAndUsername = domain + @"\" + username;
            string         displayName       = null;
            DirectoryEntry entry             = GetDirectoryEntryByUserName(username);

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfoe2 entry " + entry);
            string _path = "";

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo");

            Hashtable getDataHash = null;


            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo2");
                DirectorySearcher search = new DirectorySearcher(entry);
                if (entry != null)
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo21" + entry.Name);
                }
                else
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo21 entryis nullm ");
                }

                if (search != null)
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo22" + search.Filter);
                }
                else
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo22 search nulll m ");
                }
                search.Filter = "(SAMAccountName=" + username + ")";
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfoe123  " + search.Filter);
                search.PropertiesToLoad.Add("cn");
                search.PropertiesToLoad.Add("samaccountname");

                SearchResult result = search.FindOne();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfoe124  " + result.Path);
                DirectoryEntry userentry = result.GetDirectoryEntry();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo3");
                if (null == result)
                {
                    return(null);
                }

                //Update the new path to the user in the directory.
                _path       = result.Path;
                displayName = (string)result.Properties["cn"][0];
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo4");
                getDataHash = GetUserInfo(displayName, result.Path);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo5");
                // userentry.Invoke("SetPassword", new object[] { "ooty@4567" });
                // userentry.Properties["LockOutTime"].Value = 0;

                userentry.Close();
            }
            catch (Exception ex)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "IsAuthenticateduserinfo6" + ex.Message);
                throw new Exception("Error authenticating user. " + ex.Message);
            }

            return(getDataHash);
        }
Ejemplo n.º 14
0
        public Hashtable GetUserInfo(string userName, string path)
        {
            DirectorySearcher search = new DirectorySearcher(path);

            SSAErrorLog logObj = new SSAErrorLog();

            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get user info 1");

            search.Filter = "(&(objectClass=user)(cn=" + userName + "))";
            logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get user info 2" + userName);
            // search.Filter = "(&(objectClass=user)(samaccountname=" + userName + "))";

            //search.Filter = "(cn=" + _filterAttribute + ")";
            SearchResultCollection sResults = null;
            string    colStr  = "";
            Hashtable getData = null;

            try
            {
                getData  = new Hashtable();
                sResults = search.FindAll();

                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get user info 2" + sResults.Count);

                //loop through results of search
                foreach (SearchResult searchResult in sResults)
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "searching propss...1 ");
                    int         propCount = searchResult.Properties.Count;
                    ICollection coll      = searchResult.Properties.PropertyNames;

                    //ResultPropertyValueCollection valueCollection =
                    //        searchResult.Properties["lastlogontimestamp"];
                    //ResultPropertyValueCollection passwordExpired =
                    //        searchResult.Properties["userAccountControl"];

                    //ResultPropertyValueCollection passwordchanged =
                    //        searchResult.Properties["whenchanged"];

                    //ResultPropertyValueCollection passwordexpires =
                    //        searchResult.Properties["accountexpires"];

                    //ResultPropertyValueCollection whencreated =
                    //        searchResult.Properties["whencreated"];

                    //ResultPropertyValueCollection lockouttime =
                    //        searchResult.Properties["lockouttime"];

                    ResultPropertyValueCollection principalname =
                        searchResult.Properties["name"];
                    //ResultPropertyValueCollection emailid =
                    //        searchResult.Properties["mail"];
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "searching propss...2 ");
                    ResultPropertyValueCollection mobileno =
                        searchResult.Properties["mobile"];

                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "searching propss...3 " + "mobileno obj " + mobileno);
                    //int m_Val1 = (int)searchResult.Properties[""]..Properties["userAccountControl"]..Value;

                    //int m_Val1 = Int32.Parse(passwordExpired[0].ToString());
                    //int m_Val2 = (int)0x10000;
                    //bool m_Check = false;
                    //if (Convert.ToBoolean(m_Val1 & m_Val2))
                    //{
                    //    m_Check = true;
                    //} //end
                    //if (m_Check)
                    //    getData.Add("passwordexpired", "Expired");
                    //else
                    //    getData.Add("passwordexpired", "Not Expired");

                    //getData.Add("lastlogontimestamp", DateTime.FromFileTime((long)valueCollection[0]).ToLongDateString());

                    //getData.Add("whencreated", whencreated[0].ToString());
                    //if (lockouttime[0].ToString().Equals("0"))
                    //{
                    //    getData.Add("lockouttime", "Active, Not Locked");
                    //}
                    //else
                    //    getData.Add("lockouttime", "Not Active, Locked");

                    //getData.Add("pwdlastchanged", passwordchanged[0].ToString());

                    getData.Add("principalname", principalname[0].ToString());
                    // getData.Add("emailid", emailid[0].ToString());
                    // logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "mobileno count  ??   " + mobileno.Count);
                    if (mobileno != null)

                    {
                        if (mobileno.Count > 0)
                        {
                            // logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "mobileno count  ??   " + mobileno.Count);

                            //logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "mobileno[0].ToString()  " + mobileno[0].ToString());
                            getData.Add("mobileno", mobileno[0].ToString());
                        }
                    }
                    else
                    {
                        logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "no mobileno  ()  ");
                    }
                }
            }
            catch (Exception ex)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get user info excep" + ex.Message);
                throw new Exception("Error obtaining group names. " + ex.Message);
            }
            return(getData);
        }
Ejemplo n.º 15
0
        public void sendSMS(string mobileno, string message)
        {
            SSAErrorLog logObj = new SSAErrorLog();

            try
            {
                string webTarget = ConfigurationManager.AppSettings["smsurl"].ToString() + "&tname=tqbook&login=tqbook&to=" + mobileno + "&text=" + message;
                //string url = "http://172.32.0.175:8080/mConnector/dispatchapi?cname=tqbook&tname=tqbook&login=tqbook&to=mobilenumber&text=textmessage"


                //string url = String.Format(webTarget, mobileno);
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(webTarget);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "webtarget url  " + webTarget);


                // req.Proxy = GlobalProxySelection.GetEmptyWebProxy();
                string proxyAddress;
                proxyAddress = ConfigurationManager.AppSettings["proxyadd"].ToString();
                //proxyadd
                IWebProxy proxy = req.Proxy;
                // Print the Proxy Url to the console.
                if (proxy != null)
                {
                    Console.WriteLine("Proxy: {0}", proxy.GetProxy(req.RequestUri));

                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "proxy is there  ...  " + proxy.GetProxy(req.RequestUri));

                    WebProxy myProxy = new WebProxy();
                    Uri      newUri  = new Uri(proxyAddress);
                    myProxy.Address = newUri;
                    //adminuser
                    //adminpwd
                    myProxy.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["adminuser"].ToString(), ConfigurationManager.AppSettings["adminpwd"].ToString());
                    req.Proxy           = myProxy;
                }
                else
                {
                    Console.WriteLine("Proxy is null; no proxy will be used");
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Proxy is null; no proxy will be used  ");
                }



                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Connected to sms server ");
                req.Method = "POST";
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Connected to sms server 2");
                req.ContentType = "application/x-www-form-urlencoded";
                byte[] postData = Encoding.ASCII.GetBytes(message);
                req.ContentLength = postData.Length;
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Connected to sms server 3");
                // Set HTTP authorization header.
                //string authInfo = userName + ":" + password;
                //authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
                //req.Headers["Authorization"] = "Basic " + authInfo;

                // Send HTTP request.
                Stream PostStream = req.GetRequestStream();
                //HttpWebResponse myWebResponse = (HttpWebResponse)req.GetResponse();
                PostStream.Write(postData, 0, postData.Length);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "request sent  ");
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "get request ");
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), res.StatusDescription + " " + res.StatusCode);
            }
            catch (Exception er)
            {
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), er.Message);
            }
        }
Ejemplo n.º 16
0
        protected bool validateOTP()
        {
            SSAErrorLog logObj = new SSAErrorLog();

            string userid = null;

            try
            {
                if (Session["userid"] != null)
                {
                    userid = Session["userid"].ToString();
                }
                else if (Session["forgetpwduser"] != null)
                {
                    userid = Session["forgetpwduser"].ToString();
                }

                DatabaseLayer dataObj = new DatabaseLayer();
                userid = QASecurity.Encryptdata(userid);

                ArrayList colNames = new ArrayList();
                colNames.Add("iduserotp");
                colNames.Add("username");
                colNames.Add("otp");
                colNames.Add("otpcreatedatetime");
                colNames.Add("otpactivate");

                Hashtable updateHash = new Hashtable();
                updateHash.Add("otpactivate", 1);
                ArrayList resulthash = dataObj.getTableDataQuery("iduserotp,username,otp,otpcreatedatetime,otpactivate from userotp where username='******'", null, "iduserotp", colNames);


                string dbotp = resulthash[2].ToString();
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "User idd " + userid + " << dbotp >>>" + dbotp);
                DateTime otpdateObj = Convert.ToDateTime(resulthash[3].ToString());

                string   activate = resulthash[4].ToString();
                DateTime current  = DateTime.Now;

                TimeSpan ts   = current - otpdateObj;
                int      mins = ts.Minutes;
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "difference mins   " + mins);
                string otpvalidation     = ConfigurationManager.AppSettings["otpdurationvalidation"].ToString();
                string otpdurationinmins = ConfigurationManager.AppSettings["otpdurationinmins"].ToString();
                int    otpduration       = Convert.ToInt32(otpdurationinmins);
                logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "otpduration    " + otpduration);
                if (otpvalidation.Equals("yes"))
                {
                    if (mins > otpduration)
                    {
                        return(false);
                    }
                }
                if (dbotp.Equals(otpval.Text) && activate.Equals("False"))
                {
                    //Response.Redirect("wer.aspx");
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "done   ");
                    //here it shoud deactivate the OTP, update the table
                    //dataObj.updateTableData("userotp", updateHash, "username='******'");

                    return(true);
                }
                else
                {
                    logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), " none  ");
                    return(false);
                }

                //dataObj.getTableData("",
            }
            catch (Exception er)
            {
                return(false);
            }
        }