1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-11-09 09:50:07 +00:00

[#6] Add support for xkcd separator to CLI / WebUI

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-12-01 13:29:08 +01:00
parent 0fd3be1d52
commit 2f3688a0da
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
8 changed files with 2218 additions and 2190 deletions

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,7 @@ func getCmdGet() *cobra.Command {
cmd.Flags().BoolVarP(&flags.CLI.SpecialCharacters, "special", "s", false, "use special characters in your password")
cmd.Flags().BoolVarP(&flags.CLI.XKCD, "xkcd", "x", false, "use XKCD style password")
cmd.Flags().StringVar(&flags.CLI.Separator, "separator", "", "add separator between words of XKCD style password")
cmd.Flags().BoolVarP(&flags.CLI.PrependDate, "date", "d", true, "prepend current date to XKCD style passwords")
cmd.Flags().Bool("check-hibp", false, "Check HaveIBeenPwned for this password")
@ -37,6 +38,8 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
err error
)
pwd.DefaultXKCD.Separator = flags.CLI.Separator
for i := 0; i < flags.CLI.Num; i++ {
regenerate:

View file

@ -42,15 +42,19 @@ func handleAPIGetPasswordv1(res http.ResponseWriter, r *http.Request) {
if err != nil {
length = 20
}
special := r.URL.Query().Get("special") == "true"
xkcd := r.URL.Query().Get("xkcd") == "true"
prependDate := r.URL.Query().Get("date") != "false"
xkcdSeparator := r.URL.Query().Get("separator")
if length > 128 || length < 4 {
http.Error(res, "Please do not use length with more than 128 or fewer than 4 characters!", http.StatusNotAcceptable)
return
}
pwd.DefaultXKCD.Separator = xkcdSeparator
var password string
if xkcd {
password, err = pwd.DefaultXKCD.GeneratePassword(length, prependDate)

View file

@ -9,6 +9,7 @@ var flags = struct {
XKCD bool
PrependDate bool
Separator string
}
Server struct {

View file

@ -2,10 +2,13 @@ module github.com/Luzifer/password/cmd/password
go 1.12
replace github.com/Luzifer/password/v2 => ../../
require (
github.com/Luzifer/go_helpers/v2 v2.9.1
github.com/Luzifer/password/v2 v2.0.1
github.com/Luzifer/password/v2 v2.1.0
github.com/gorilla/mux v1.7.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e // indirect

View file

@ -1,11 +1,17 @@
github.com/Luzifer/go_helpers/v2 v2.9.0/go.mod h1:nF5Xu5C2TgCuejZWoXVpS6KnX3LDefFBM5+qQ87hEto=
github.com/Luzifer/go_helpers/v2 v2.9.1 h1:MVUOlD6tJ2m/iTF0hllnI/QVZH5kI+TikUm1WRGg/c4=
github.com/Luzifer/go_helpers/v2 v2.9.1/go.mod h1:ZnWxPjyCdQ4rZP3kNiMSUW/7FigU1X9Rz8XopdJ5ZCU=
github.com/Luzifer/password v2.0.0+incompatible h1:eTjnuMpUtpGITmDjAkJnzMUDoapLtGOXR3FBvqREfkc=
github.com/Luzifer/password v2.0.0+incompatible/go.mod h1:F8bbXgwczd/1vyyJ9G8Z6hPvaqtpKR9VZM0E7jkZKJc=
github.com/Luzifer/password/v2 v2.0.1 h1:p1q66RtLAXsAw3GYKKMPctavs1YQehjEoFSWMLKuo68=
github.com/Luzifer/password/v2 v2.0.1/go.mod h1:tnWOAJaV9uK92wAUmZZ2BNiZdiWCSQ/gMiaDMSyOBBM=
github.com/Luzifer/password/v2 v2.1.0 h1:Bf4Att+poXeD7UsG5k2IUZn8z8n/OI1eCnDc4TLJ354=
github.com/Luzifer/password/v2 v2.1.0/go.mod h1:tnWOAJaV9uK92wAUmZZ2BNiZdiWCSQ/gMiaDMSyOBBM=
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b/go.mod h1:thNruaSwydMhkQ8dXzapABF9Sc1Tz08ZBcDdgott9RA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View file

@ -103,6 +103,10 @@
<input type="checkbox" id="useXKCDOption"> Use <a href="https://xkcd.com/936/" target="_blank">XKCD style passwords</a>
</label>
</div>
<div class="form-group">
<label for="xkcdSeparator" class="control-label">Separator for XKCD passwords:</label>
<input type="text" class="form-control" value="" placeholder="Optional, could be '-' or any other separator" id="xkcdSeparator">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

View file

@ -41,7 +41,7 @@ let setProgress = (perc) => {
let loadPassword = () => {
let options = loadOptions()
$.get(`/v1/getPassword?length=${options.passwordLength}&special=${options.useSpecial}&xkcd=${options.useXKCD}`, (data) => {
$.get(`/v1/getPassword?length=${options.passwordLength}&special=${options.useSpecial}&xkcd=${options.useXKCD}&separator=${options.xkcdSeparator}`, (data) => {
$('#focusedInput').val(data)
window.lastLoad = now()
})
@ -52,6 +52,7 @@ let saveOptions = () => {
passwordLength: $('#passwordLengthOption').val(),
useSpecial: $('#useSpecialOption')[0].checked,
useXKCD: $('#useXKCDOption')[0].checked,
xkcdSeparator: $('#xkcdSeparator').val(),
}
storage.set('SecurePasswordOptions', options)
@ -67,11 +68,13 @@ let loadOptions = () => {
passwordLength: 20,
useSpecial: false,
useXKCD: false,
xkcdSeparator: '',
}
}
$('#passwordLengthOption').val(options.passwordLength)
$('#passwordLengthOption').val(options.passwordLength || 20)
$('#useSpecialOption')[0].checked = options.useSpecial
$('#useXKCDOption')[0].checked = options.useXKCD
$('#xkcdSeparator').val(options.xkcdSeparator || '')
return options
}