Code Monkey home page Code Monkey logo

htpasswd's Introduction

htpasswd

Description

htpasswd is a library for working with htpasswd user (only basic authorization) and group files.

supports both the crypt method and the MD5 encryption method.

for the md5 method you MUST have openssl installed (and it must be in the system path.) does not use python openSSL bindings, but actually calls out to openssl. Not the best security method, feel free to fix for me.

Build Status

Dependencies

Sample usage

import htpasswd

with htpasswd.Basic("/path/to/user.db") as userdb:
    try:
        userdb.add("bob", "password")
    except htpasswd.basic.UserExists, e:
        print e
    try:
        userdb.change_password("alice", "newpassword")
    except htpasswd.basic.UserNotExists, e:
        print e

with htpasswd.Group("/path/to/group.db") as groupdb:
    try:
        groupdb.add_user("bob", "admins")
    except htpasswd.group.UserAlreadyInAGroup, e:
        print e
    try:
        groupdb.delete_user("alice", "managers")
    except htpasswd.group.UserNotInAGroup, e:
        print e

to encrypt with md5, just add mode='md5' to htpasswd.Basic(userdb, mode='md5')

Provided methods

Basic

  • __contains__(user)
  • users
  • add(user, password)
  • delete(user)
  • change_password(user, password)
  • _crypt_password(password)

Group

  • __contains__(group)
  • groups
  • is_user_in(user, group)
  • add_user(user, group)
  • delete_user(user, group)

Exceptions

HtException

That's a general exception from which others are inherited.

UserExists

Raised by Basic.add if user already exists.

UserNotExists

Raised by Basic.delete and Basic.change_password if there is no such user.

GroupNotExists

Raised by Group.delete_user if there is no such group.

UserAlreadyInAGroup

Raised by Group.add_user if user is already in a group.

UserNotInAGroup

Raised by Group.delete_user if user isn't in a group.

UnknownEncryptionMode

raised by _encrypt_password if mode is not 'crypt' or 'md5'.

htpasswd's People

Contributors

csawyeryumaed avatar thesharp avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.