func runLogin()

in cmd/acr/login.go [68:125]


func runLogin(opts loginOpts) error {
	if opts.debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	store, err := oras.NewStore(opts.configs...)
	if err != nil {
		return err
	}

	var username string
	var passwordBytes []byte
	if opts.fromStdin {
		passwordBytes, err = io.ReadAll(os.Stdin)
		if err != nil {
			return err
		}
		opts.password = strings.TrimSuffix(string(passwordBytes), "\n")
		opts.password = strings.TrimSuffix(opts.password, "\r")
	} else if opts.password == "" {
		if opts.username == "" {
			username, err = readLine("Username: ", false)
			if err != nil {
				return err
			}
			opts.username = strings.TrimSpace(username)
		}
		if opts.password, err = readLine("Password: ", true); err != nil {
			return err
		} else if opts.password == "" {
			return errors.New("password required")
		}

	} else {
		fmt.Fprintln(os.Stderr, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.")
	}

	// Ping to ensure credential is valid
	remote, err := remote.NewRegistry(opts.hostname)
	if err != nil {
		return err
	}
	cred := oras.Credential(opts.username, opts.password)
	remote.Client = oras.NewClient(oras.ClientOptions{
		Credential: cred,
		Debug:      opts.debug,
	})
	if err = remote.Ping(context.Background()); err != nil {
		return err
	}
	// Store the validated credential
	if err := store.Store(opts.hostname, cred); err != nil {
		return err
	}

	fmt.Println("Login Succeeded")
	return nil
}