summaryrefslogtreecommitdiffstats
path: root/util.py
blob: e375aa1f4db6ef6ef60cc9a54a5a793669e027c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-

import config

import web
from random import Random

rng = Random()

righthand = '23456qwertasdfgzxcvbQWERTASDFGZXCVB'
lefthand = '789yuiophjknmYUIPHJKLNM'
allchars = righthand + lefthand

def generate_char(i, alternate_hands):
    if not alternate_hands:
        return rng.choice(allchars)
    else:
        if i%2:
            return rng.choice(lefthand)
        else:
            return rng.choice(righthand)


def generate_password(length = 8, alternate_hands = True):
    return ''.join([generate_char(i, alternate_hands) for i in xrange(length)])


def validate_listname(name):
    for regex in config.reserved_names:
        if re.search(regex, name):
            return False
    return True