显示登录日期问题 [英] Display Log In date Problem

查看:73
本文介绍了显示登录日期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有求职者和招聘者两个模块.
我必须在2个模块的每页中显示lastlogin日期.

我的登录代码是

I have two module in my website jobseeker and recruiter.
I have to display lastlogin date in each page of 2 modules.

my login code is

protected void btnlogin_Click(object sender, EventArgs e)
    {


        string q = "select count(*) from logdate where eid = '" + txtuname.Text.Trim() + "' and password = '" + txtpasswd.Text.Trim() + "'" ;
        cmd = new SqlCommand(q, cnn);
        object obj;
        obj = cmd.ExecuteScalar();
        if (obj.ToString() == "1")
        {
            cmd = new SqlCommand("Select * from logtable where eid ='" + txtuname.Text + "'", cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
            
            Session["eid"] = dr["eid"].ToString();
            Session["password"] = dr["password"].ToString();
            dr.Close();
            Response.Redirect("seekerhome.aspx");
        }
        else
        {
            txtuname.Text = "";
            txtpasswd.Text = "";
            lblmsg.Text = "Either E-Mail ID or Password is wrong..!";
        }

        cnn.Close();
    }




因此,您可以按照以下代码帮助我如何显示我的上次登录日期吗?
我也对这种逻辑感到困惑.




so can you help me following this code how can i display my last log in date?
I also confused in this logic also.

推荐答案


看来您没有将登录日期存储到数据库中,因此第一件事是当用户登录时,将登录日期存储在dateBase中以及下次存储时,您可以通过简单的查询将其显示给用户.
可以使用参数查询的另一件事是可以避免SQL Injections
最好的问候
M.Mitwalli
Hi,
It seems you are not storing log in date into your DataBase so the First thing is When user log in store the log in date in your dateBase and in the next time and you can show it to user by simple Query
Another thing you can use parametrize Query so you can Avoid SQL Injections
Best Regards
M.Mitwalli


始终使用参数化查询,这样就不会进行SQL注入.

Always use parameterised Query, so that SQL injection won''t be done.

protected void btnlogin_Click(object sender, EventArgs e)
    {
        string q = "select count(*) from logdate where eid = @Name and password = @Password";
        cmd = new SqlCommand(q, cnn);
        cmd.Parameters.Add("@Name",  txtuname.Text.Trim());
        cmd.Parameters.Add("@Password", txtpasswd.Text.Trim());        
        object obj;
        obj = cmd.ExecuteScalar();
        if (obj.ToString() == "1")
        {
            cmd = new SqlCommand("Select * from logtable where eid =@Name", cnn);
            cmd.Parameters.Add("@Name",  txtuname.Text.Trim());  
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
            //Put the current login time in a session here and also insert into a table for accessing it next time when user logs in again.

            Session["eid"] = dr["eid"].ToString();
            Session["password"] = dr["password"].ToString();
            dr.Close();
            Response.Redirect("seekerhome.aspx");
        }
        else
        {
            txtuname.Text = "";
            txtpasswd.Text = "";
            lblmsg.Text = "Either E-Mail ID or Password is wrong..!";
        }

        cnn.Close();
    }



谢谢
Ashish



Thanks
Ashish


您应该阅读我有关安全性的文章.您的代码容易受到sql注入的攻击,并且您存储的密码是纯文本.

初学者指南介绍了一种安全的密码存储方式 [ ^ ]

要显示上次登录日期,只需在用户成功登录后立即将日期存储在表中即可.
You should read my article about security. Your code is vulnerable for sql-injections and you are storing passwords are clear text.

Beginners guide to a secure way of storing passwords[^]

To show last login date, just store the date now in your table when a user is logging in successfully.


这篇关于显示登录日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆