-1

i am developing an application in asp.net of which i want to create a DEMO version for 7 days.. i tried to make the demo stop in asp.net by checking for the current date and if its past 7 days then the application. wont start. but the problem is the user changes the date from windows control panel then application. wont detect it and it will run.. i want take cmos date/time Without Online

int num=7;  
int smonth=convert.toint32(Datetime.Now.Date.Tostring());  

             if ((num < smonth) || (num == smonth))
            {

                ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true);
            }

            else
            {
                if (crt_val == "0")
                {

                    Session["UserId"] = txtusername.Text.Trim();
                    objuser.UserCode = txtusername.Text.Trim();
                    objuser.Password = s_hex_md5(txtpassword.Text.Trim());
                    string pwd = s_hex_md5(txtpassword.Text);
                    objuser.Ccode = ddlCode.SelectedValue;
                    objuser.Lcode = ddlLocation.SelectedValue;
                    DataTable dt = new DataTable();
                    dt = objdata.UserLogin(objuser);
                    if (dt.Rows.Count > 0)
                    {
                        if ((dt.Rows[0]["UserCode"].ToString().Trim() == txtusername.Text.Trim()) && (dt.Rows[0]["Password"].ToString().Trim() == pwd) && (dt.Rows[0]["CompCode"].ToString().Trim() == ddlCode.SelectedValue) && (dt.Rows[0]["LocationCode"].ToString().Trim() == ddlLocation.SelectedValue))
                        {
                            Session["Isadmin"] = dt.Rows[0]["IsAdmin"].ToString().Trim();
                            Session["Usernmdisplay"] = txtusername.Text.Trim();
                            Session["Ccode"] = dt.Rows[0]["CompCode"].ToString().Trim();
                            Session["Lcode"] = dt.Rows[0]["LocationCode"].ToString().Trim();
                            if (Session["Isadmin"].ToString() == "1")
                            {
                                Session["RoleCode"] = "1";
                            }
                            else
                            {
                                Session["RoleCode"] = "2";
                            }
                            Response.Redirect("Dashboard.aspx");
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('User Name and Password Wrong');", true);

                        }

                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true);

                    }
                }
                else
                { }

            }

Anyone help me...

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Parthi
  • 21
  • 5
  • 1
    Asking the same question one day later will *NOT* change the fact that trying to get the BIOS time is pointless, or that the posted code is not relevant – Panagiotis Kanavos Dec 24 '13 at 09:52
  • How do you thing *this* `convert.toint32(Datetime.Now.Date.Tostring())` is going to work? `ToInt32` doesn't recognize textual representation of dates and times. And it even doesn't compile. – Ondrej Tucny Dec 24 '13 at 09:52

2 Answers2

1

When user changes the time in control panel, the user IS changing the CMOS date/time.

You might want to have your application contact a time server online to get the correct date/time.

Excellent answer on how to do it here

https://stackoverflow.com/a/12150289/263003

Community
  • 1
  • 1
Jeow Li Huan
  • 3,758
  • 1
  • 34
  • 52
0

DateTime structure in C# gives you the date and time details from the machine where the code is running. so if you want to give a demo application to the client you can deploy the application on the Server which is under your control. so that user does not have the control to change the date and time, even if the client changes date and time it wont effect the Application as the Application code is running on different machine.

DateTime.Now gives you the Current date and time of the Server

so i would suggest to maintain a dedicated server for deploying/maintaining the website for client.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67