Standard library / net/smtp

smtp.CRAMMD5Auth()

Create the historical CRAM-MD5 challenge-response mechanism. This legacy MD5-based mechanism is not a modern security recommendation. Expected stdout: 'CRAM-MD5 true 37\n'.

Formal Syntax & Structure

go syntaxgo
func CRAMMD5Auth(username, secret string) Auth

Parameters & Attributes

NameTypeDescription
usernamestringSynthetic or configured authentication user name.
secretstringShared authentication secret; never log it.

Return Value

Auth

Authentication mechanism implementing historical CRAM-MD5.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/smtp"  "strings")
func main() {  a := smtp.CRAMMD5Auth("demo", "synthetic")  p, _, e := a.Start(&smtp.ServerInfo{})  check(e)  v := must(a.Next([]byte("challenge"), true))  fmt.Println(p, strings.HasPrefix(string(v), "demo "), len(v))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference