MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / Write

Method Write

cmd/pad/cmd_auth_2fa_test.go:460–480  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

458}
459
460func (w *codeTypingWriter) Write(p []byte) (int, error) {
461 n, _ := w.buf.Write(p)
462 if strings.Contains(string(p), "Password: ") {
463 go func() { _, _ = w.pw.Write([]byte(twoFAPassword + "\n")) }()
464 }
465 if strings.Contains(string(p), "Code from the app: ") {
466 w.prompts++
467 m := secretLine.FindStringSubmatch(w.buf.String())
468 code := "000000"
469 if m != nil {
470 if c, err := totp.GenerateCode(m[1], time.Now()); err == nil {
471 code = c
472 }
473 }
474 if w.prompts <= w.wrongFirst {
475 code = wrongCode(code)
476 }
477 go func() { _, _ = w.pw.Write([]byte(code + "\n")) }()
478 }
479 return n, nil
480}
481
482// wrongCode changes a code's first digit, so it can never be the valid one.
483func wrongCode(code string) string {

Callers 1

TestTask4509SetupStepUpFunction · 0.45

Calls 3

wrongCodeFunction · 0.85
NowMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected