示例#1
0
	def __cb_response(self, widget, response):
		"Callback for dialog responses"

		if response == gtk.RESPONSE_OK:
			self.entry.set_text(util.generate_password(self.spin_pwlen.get_value()))

		else:
			self.destroy()
示例#2
0
    def __cb_response(self, widget, response):
        "Callback for dialog responses"

        if response == gtk.RESPONSE_OK:
            self.entry.set_text(
                util.generate_password(self.spin_pwlen.get_value()))

        else:
            self.destroy()
示例#3
0
def create_holder(weixin, mobile, address, realname, portal='login.html', billing=0):
    '''
        portal : authentication page
        billing : billing type
            0 : normal billing type (coin & expire_date)
            1 : free
    '''
    password = util.generate_password()
    now = util.now('%Y-%m-%d %H:%M:%S')

    _id = db.add_holder(weixin, password, mobile, now, 
                        address=address, realname=realname, 
                        portal=portal, billing=billing)
    return _id
示例#4
0
def check_weixin_account(appid, openid):
    '''
        check openid existed?
            exist : return
            not exist : create account
    '''
    _user = db.get_account(appid=appid, weixin=openid) or db.get_account2(appid=appid, weixin=openid)

    if not _user:
        # create account
        _user = db.add_user(openid, util.generate_password(), appid=appid, ends=2**5)
    else:
        if _user['amask']>>28 & 1:
            _user['amask'] = _user['amask'] ^ 1<<28
            db.update_account(_user['user'], mask=_user['amask'])

    return _user
def create_user():
    """Creates a new user in the package index's user access controls system.

    Create a new user in the user access controls service for the package index.
    This causes an email to be sent to the new user with a temporary password.

    Form-encdoded params:

     - ```username``` The name of the new user.
     - ```email``` The email address for the new user.

    JSON-document returned:

     - ```success``` Boolean value indicating if successful. Will be true if new
       user created and false otherwise.
     - ```message``` Deatails about the result of the operation. Will be
       provided in both the success and failure cases.

    @return: JSON document
    @rtype: flask.response
    """
    username = flask.request.form['username']
    email = flask.request.form['email']

    if db_adapter.get_user(username):
        return json.dumps(util.create_error_message(
            'A user with that username or email address already exists.'
        ))

    if db_adapter.get_user_by_email(email):
        return json.dumps(util.create_error_message(
            'A user with that username or email address already exists.'
        ))

    new_password = util.generate_password()
    password_hash = generate_password_hash(new_password)
    db_adapter.put_user({
        'username': username,
        'email': email,
        'password_hash': password_hash
    })
    email_service.send_password_email(app, email, username, new_password)
    return json.dumps(util.create_success_message('User account created.'))
示例#6
0
def check_account_by_mobile_or_mac(mobile, mac):
    '''
        1. first check mac_history 
         
        2. check user has been register?
               mobile : 
               mac : android register by mac address 
    '''
    _user = db.get_account_by_mobile_or_mac(mobile, mac)
    if not _user:
        # register account by mobile
        password = util.generate_password()
        _user = db.add_user(mobile, password, mobile=mobile, ends=2**8)
        _user['existed'] = 0
        # _user = {'user':user, 'password':password, 'existed':0}
    else:
        if _user['amobile'] != mobile or _user['mobile'] != mobile:
            db.update_account(_user['user'], mobile=mobile)

        _user['existed'] = 1
    return _user
def reset_user_password(username):
    """Resets a user's password for manipulating the package index.

    JSON-document returned:

     - ```success``` Boolean value indicating if successful. Will be true if the
       user was updated and false otherwise.
     - ```message``` Details about the result of the operation. Will be provided
       in both the success and failure cases.

    @param username: The name of the user to modify as read from the url.
    @type username: str
    @return: JSON document
    @rtype: flask.response
    """
    if not db_adapter.get_user(username):
        return json.dumps(util.create_error_message(
            'Whoops! There was an error on the server.'
        ))

    new_password = util.generate_password()
    password_hash = generate_password_hash(new_password)
    db_adapter.put_user({
        'username': username,
        'password_hash': password_hash
    })

    user_info = db_adapter.get_user(username)

    email_service.send_password_email(
        app,
        user_info['email'],
        username,
        new_password
    )
    return json.dumps(util.create_success_message(
        'Password reset. Please check your email inbox.'
    ))
示例#8
0
文件: user_auth.py 项目: quru/qis
def authenticate_user(username, password, data_engine, logger):
    """
    Authenticates the given user credentials, returning the associated User
    object on success, or None if either the username or password is incorrect.

    If LDAP integration is enabled, a new image server user account will be
    created if there is no existing account but the username and password are
    valid on the LDAP server.

    An AuthenticationError is raised if an error occurrs performing the
    authentication process.
    """
    try:
        logger.debug('Authenticating user \'' + username + '\'')
        user = data_engine.get_user(username=username)

        if user is not None:
            if user.auth_type == User.AUTH_TYPE_PASSWORD:
                # Standard authentication
                auth = user.check_password(password)
                auth_type = 'Standard'
            elif user.auth_type == User.AUTH_TYPE_LDAP:
                # LDAP authentication
                auth, _ = _authenticate_ldap(username, password, logger)
                auth_type = 'LDAP'
            else:
                raise AuthenticationError('Unsupported authentication type')

            logger.debug(
                auth_type + ' authentication ' + ('OK' if auth else 'failed') +
                ' for \'' + username + '\''
            )
            # Return result for known username
            return user if auth else None
        else:
            # The username is not known locally
            if app.config['LDAP_INTEGRATION']:
                logger.debug('Checking LDAP server for unknown user \'' + username + '\'')
                auth, user_attrs = _authenticate_ldap(username, password, logger)
                if auth:
                    # Valid LDAP user, auto-create a new user account
                    logger.debug(
                        'Identified user \'' + username + '\' on LDAP server, ' +
                        'authentication OK, creating new user account'
                    )
                    logger.debug('User details: ' + str(user_attrs))
                    (firstname, lastname) = _get_firstname_lastname(user_attrs)
                    new_user = User(
                        firstname,
                        lastname,
                        '',
                        username,
                        generate_password(),  # This won't get used...
                        User.AUTH_TYPE_LDAP,  # as long as this flag still says LDAP
                        False,
                        User.STATUS_ACTIVE
                    )
                    data_engine.create_user(new_user)
                    return new_user
                else:
                    logger.debug('LDAP authentication failed for \'' + username + '\'')
                    return None

            # Unknown username
            logger.debug('Unknown user \'' + username + '\'')
            return None

    except AuthenticationError as e:
        raise
    except Exception as e:
        raise AuthenticationError(str(e))
示例#9
0
文件: ui.py 项目: dcreager/revelation
	def generate(self):
		"Generates a password for the entry"

		password = util.generate_password(self.config.get("passwordgen/length"))
		self.pwentry.set_text(password)
示例#10
0
def check_app_account(uuid, mask):
    _user = get_account(uuid=uuid)
    if not _user:
        _user = db.add_user(uuid, util.generate_password(), ends=mask)
    return _user