#python #linux and check (and delete if existing) a user

import pwd
 
def check_user_and_delete(user):
    try:
        if pwd.getpwnam(user) is True:
            res = sudo("userdel {}".format(user))
        if res.return_code == 0:
            print "== > User {} deleted".format(user)
        else:
            print "== > User {} not deleted".format(user)
    except KeyError:
            pass

I just love #python

def bits(n):
    res = ''
    """
    Generates the binary digits of n
    """
    while n:
        res+= str(n & 1)
        n >>= 1
    return res[::-1]

User Key Generation

Little idea for a code to associate to a user

#!/usr/bin/env python
#
# Author: Luca Francesca
# A function for key generation
#

import random
import string

def keyGen(uname, pwd):
key = random.choice(string.lowercase)
key += uname[1:4]
key += pwd[2:4] + random.choice(string.uppercase)
key += random.choice(string.lowercase)
key += str(random.randint(2,9))
key += str(random.randrange(1,10) * 3)
key += random.choice(string.uppercase)
key += random.choice(string.lowercase)
key += str(random.randint(random.randint(1,50) ,random.randint(50,70)))
return key;

if __name__ == ‘__main__’:
print keyGen(‘luca’, ‘luca’)
print keyGen(‘marco’, ‘marco’)