password

package module
v0.0.0-...-9ed6612 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2013 License: BSD-3-Clause Imports: 6 Imported by: 6

README

Reading Password on the Command Line in Go
==========================================

Some of the code in this package is taken from
`code.google.com/p/go/crypto/ssh/terminal`_ and then has been modified
by Jochen Voss.  The original code is distributed under the following
license::

    Copyright 2011 The Go Authors. All rights reserved.
    Use of this source code is governed by a BSD-style
    license that can be found in the LICENSE file.

All added code and all changes to the original code are distributed
under the following license::

    Copyright 2013 Jochen Voss. All rights reserved.
    Use of this source code is governed by a BSD-style
    license that can be found in the LICENSE file.

.. _code.google.com/p/go/crypto/ssh/terminal: https://code.google.com/p/go/source/browse/?repo=crypto#hg%2Fssh%2Fterminal


Installation
------------

This package can be installed using the ``go get`` command::

    go get github.com/seehuhn/password

Usage
-----

The following command can be used to read a password from the command
line::

    input, err := password.Read("passwd: ")

This switches of echoing of input to the terminal, prints the given
prompt to the screen, reads input from standard input until the end of
line, and finally restores the original terminal settings.  The byte
slice returned does not include the terminating end-of-line character.

Documentation

Overview

Package password provides a function to read passwords on the command line on Linux and BSD Unix (including MacOS X) systems.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyboardInterrupt = errors.New("keyboard interrupt")

Functions

func Read

func Read(prompt string) ([]byte, error)

Read prints the given prompt to standard output and then reads a line of input from standard input with echoing of input disabled. This is commonly used for inputting passwords and other sensitive data. The byte slice returned does not include the terminating "\n".

func ReadWithTimings

func ReadWithTimings(prompt string, timings chan<- time.Time) ([]byte, error)

ReadWithTimings prints the given prompt to standard output and then reads a line of input from standard input with echoing of input disabled. This is commonly used for inputting passwords and other sensitive data. The byte slice returned does not include the terminating "\n".

The time of every keypress during password input is written into the channel 'timings'. This allows to use password input to gather entropy for a random number generator. Care must be taken to not disclose these timings to an attacker: there is correlation between keys pressed and the times between key presses.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL