Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reset password #1119

Merged
merged 4 commits into from
May 19, 2024
Merged

feat: reset password #1119

merged 4 commits into from
May 19, 2024

Conversation

jeessy2
Copy link
Owner

@jeessy2 jeessy2 commented May 18, 2024

What does this PR do?

fix: #1100 #1022 #934 #554

  • Encrypt password using bcrypt
  • Add reset password function

Motivation

Additional Notes

@WaterLemons2k
Copy link
Contributor

如果加密密码已成定局的话,建议使用 go-keying 库。(也被 GitHub CLI 使用

可以使用此库先将密码保存到系统自带的密钥环(keyring)中,不行再保存到配置文件中。

参考:https://stackoverflow.com/questions/33183692

@jeessy2
Copy link
Owner Author

jeessy2 commented May 19, 2024

如果加密密码已成定局的话,建议使用 go-keying 库。(也被 GitHub CLI 使用

可以使用此库先将密码保存到系统自带的密钥环(keyring)中,不行再保存到配置文件中。

参考:https://stackoverflow.com/questions/33183692

有些系统可能不支持吧。不行再保存至配置文件中,这样感觉更加复杂了

Copy link
Contributor

@WaterLemons2k WaterLemons2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复杂度确实无解,放弃了。

util/bcrypt.go Outdated
}

// CheckPassword 检查密码
func CheckPassword(hashedPassword, password string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数名和 config 包里的冲突,干的活也不一样,容易混淆。可以尝试改名叫 PasswordOK


// CheckPassword 检查密码
func (conf *Config) CheckPassword(newPassword string) (hashedPwd string, err error) {
var minEntropyBits float64 = 50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当时定的强度有点高,可以调低点

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外网访问50,差不多。内网25

main.go Outdated
var customDNS = flag.String("dns", "", "Custom DNS server address, example: 8.8.8.8")

// 重置密码
var newPassword = flag.String("password", "", "Reset password")
Copy link
Contributor

@WaterLemons2k WaterLemons2k May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var newPassword = flag.String("password", "", "Reset password")
var resetPassword = flag.String("resetPassword", "", "Reset password to the one entered")

如果不看描述的话,看不出来这个标志到底是用来重置密码,还是用传递的密码登录的。

可以改为使用 bool 标志,然后随机生成一个密码或者从 stdin 读取。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md中有说明,也有描述。
改为使用 bool 标志,然后随机生成一个密码或者从 stdin 读取。 感觉稍微复杂了

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

描述:Reset password, example: ./ddns-go -password 123456?

Copy link
Contributor

@WaterLemons2k WaterLemons2k May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

描述:Reset password, example: ./ddns-go -password 123456?

重置密码是个低频操作,把标志名改成 resetPassword 应该就够了,不需要示例。

-resetPassword string
        Reset password to the one entered

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以

@jeessy2 jeessy2 merged commit eda1050 into master May 19, 2024
4 checks passed
@jeessy2 jeessy2 deleted the reset_password branch May 19, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

不要明文存储密码在配置文件内
2 participants