简体   繁体   English

安全地在数据库中存储1个密码

[英]Storing 1 password in database securely

I have a java swing application which starts with a login page and should take admin to the dashboard if the login is authenticated. 我有一个Java swing应用程序,该应用程序从登录页面开始,如果登录经过验证,则应将admin转到仪表板。 As there is just 1 admin, so there is just 1 username and password combination. 由于只有1个管理员,因此只有1个用户名和密码组合。

Right now, I am just inserting username and password to the sql table using a simple insert query. 现在,我只是使用简单的插入查询将用户名和密码插入sql表。 I am new at this so I don't know how to go about this 我是新来的,所以我不知道该怎么做

create table login (
    Emp_id INT AUTO_INCREMENT PRIMARY KEY,
    Emp_Fname VARCHAR(50),
    Emp_Lname VARCHAR(50),
    Username VARCHAR(50),
    Password VARCHAR(50)
);
insert into login (Emp_id, Emp_Fname, Emp_Lname, Username, Password) values (1, 'TestFName', 'TestLName', 'Test', 'Test');

Instead of storing passwords in plain text, I want it encrypted or hash. 我希望将其加密或散列,而不是将密码存储为纯文本格式。

I am currently typing from my phone so forgive me. 我目前正在用手机打字,请原谅。 It seems like u want your password to look like: eive29ceic28e8c38d9h3ce9h instead of "password123" 您似乎希望您的密码看起来像:eive29ceic28e8c38d9h3ce9h而不是“ password123”

You can use something like SHA-1, which have an integration in java with SHA256 and SHA512. 您可以使用SHA-1之类的东西,它在Java中与SHA256和SHA512集成在一起。 Both of which can be found after a quick Google search. 两者都可以在Google快速搜索后找到。 I personally used them in a project but ran recursively this method 100 times using the result from one round as the input for the next. 我个人在项目中使用了它们,但是使用一个回合的结果作为下一回合的输入来递归运行此方法100次。 Then I extended the length of the string by using this scheme: password + password backwards + password + password. 然后,我使用以下方案扩展了字符串的长度:密码+向后密码+密码+密码。 In my case the password got 4x512 bits long and seemed relatively secure. 在我的情况下,密码的长度为4x512位,似乎相对安全。 After that I saved it to a file and every time I want to login, I take the input and encrypt it and then compare it to my password in my file. 之后,我将其保存到文件中,并且每次我要登录时,都将输入内容加密并加密,然后将其与文件中的密码进行比较。 If they match you're in. I know that you can crack sha-1 opens it brute force. 如果它们匹配,您就可以进入。我知道您可以破解sha-1打开它的蛮力。 If you want something different try bcrypt, pbkdf2 or argon2. 如果您需要其他内容,请尝试使用bcrypt,pbkdf2或argon2。

I would like to give you links but that's hard on mobile. 我想给你链接,但是在手机上很难。 I hope this works iut for you. 我希望这对您有用。 Otherwise I will comment tomorrow morning 否则我明天早上会发表评论

Edit: look into your comments there is a link to the algorithm I meant. 编辑:查看您的评论,有指向我所指算法的链接。 Just put it in a for loop 100 times... 只需将其放入for循环100次...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM