Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 31a3cfc

Browse files
eraydmax-baz
authored andcommitted
Allow using a bare TOTP token instead of an otpauth:// URL (#226)
1 parent 91179ae commit 31a3cfc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

browserpass.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,16 @@ func readLoginGPG(r io.Reader) (*Login, error) {
179179
}
180180

181181
func parseTotp(str string, l *Login) error {
182-
re := regexp.MustCompile("^otpauth.*$")
183-
ourl := re.FindString(str)
184-
182+
urlPattern := regexp.MustCompile("^otpauth.*$")
183+
ourl := urlPattern.FindString(str)
184+
185+
if ourl == "" {
186+
tokenPattern := regexp.MustCompile("(?i)^totp(-secret)?:")
187+
token := tokenPattern.ReplaceAllString(str, "");
188+
if len(token) != len(str) {
189+
ourl = "otpauth://totp/?secret=" + strings.TrimSpace(token)
190+
}
191+
}
185192
if ourl != "" {
186193
o, label, err := twofactor.FromURL(ourl)
187194
if err != nil {
@@ -215,6 +222,11 @@ func parseLogin(r io.Reader) (*Login, error) {
215222
}
216223
}
217224

225+
// if an unlabelled OTP is present, label it with the username
226+
if strings.TrimSpace(login.OTPLabel) == "" && login.OTP != "" {
227+
login.OTPLabel = login.Username
228+
}
229+
218230
return login, nil
219231
}
220232

0 commit comments

Comments
 (0)