检查日期是否更改 [英] Check whether the date changed

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

问题描述

我正在处理Java Swing中的考勤项目。登录应该只有一天一次。

I am working on an attendance project in Java Swing. Log in should be only once a day.

我的项目包含登录页面,其中包含用户名和密码的数据库,我只想确保登录(为员工更新的考勤)

My project contains of login page which has a database from which user names and passwords are given, I just want to make sure that login (attendance updated for an employee) takes place only once a day.

如何检查日期是否改变?

How to check whether the date changed?

推荐答案

如果某人每天登录超过一次,真的很重要吗?实际上,你的要求有一个欺骗问题。假设一个同事偷了我的密码,他用它来作为我登录。然后我进来,我现在无法登录。最好允许用户随时登录,并显示一条消息您最后一次在2013年6月3日上午8:45登录。

Does it really matter if someone logs in more than once a day? Actually, your requirement has a spoofing problem. Suppose that a coworker stole my password, and he used it to log in as me. Then I come in, and I now cannot log in. It's better to allow users to log in whenever they want, and to show a message "You last logged in at 8:45 AM EDT on 3 June 2013".

如果您需要此确切需求,请将最后一个登录日期作为SQL DATE类型存储在数据库中,该类型没有时间。让登录代码看起来像

If you need this exact requirement, store the last login date in the database as a SQL DATE type, which does not have time-of-day. Have the login code look like

PreparedStatement ps = conn.prepareStatement(
    "SELECT last_logon FROM USERS WHERE username = ? AND passwordHash = ?");
// Please don't store the password itself in the database.
ps.setString(1, username);
ps.setString(2, sha1(password, salt)); // very vague, I know.
ResultSet rs = ps.executeQuery();
if (rs.next()) {
    java.sql.Date lastLogin = rs.getDate("last_logon");
    // Check that last_logon isn't today.
    // Use an UPDATE to update the field.
}

这真的不是Swing特有的,您将需要查看数据库如何计算消息哈希值,以及如何将salt应用于密码。你需要决定盐源。

This really isn't Swing-specific, or even Java-specific. You'll want to look at how your database can compute message hashes, and how you can apply salt to the passwords. You'll need to decide the salt source.

这篇关于检查日期是否更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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