def registerUsers(userList): """Registers a new set of users as specified in userList. Should be called with a large number of users for good security (prefferably all that will ever be in the system.) userList -- list of dictionaries each depicting a user with the keys: 'username', 'department', 'name', 'course' returns a list of passwords corresponding to each user """ noUsers = len(userList) passwords = [cryptography.generatePrintableRandomString() for i in range(noUsers)] publicKeys = [] for i in range(noUsers): challengeStr = cryptography.generateRandomString(128) newChallengeStr = ChallengeStrings(challengeStr=challengeStr) newChallengeStr.save() newPublicKey = addUser(userList[i]['username'], userList[i]['department'], userList[i]['name'], userList[i]['course'], userList[i]['gender'], userList[i]['hostel'], passwords[i]) publicKeys += [newPublicKey] user = User.objects.create_user(username = userList[i]['username'], password = passwords[i]) user.save() logger.info('New user added') cryptography.permuteList(publicKeys) for i in range(len(publicKeys)): newPublicKey = PublicKeys(publicKey=publicKeys[i]) newPublicKey.save() return passwords
def registerUsers(userList): """Registers a new set of users as specified in userList. Should be called with a large number of users for good security (prefferably all that will ever be in the system.) userList -- list of dictionaries each depicting a user with the keys: 'username', 'department', 'name', 'course' returns a list of passwords corresponding to each user """ noUsers = len(userList) passwords = [cryptography.generatePrintableRandomString() for i in range(noUsers)] publicKeys = [] for i in range(noUsers): challengeStr = cryptography.generateRandomString(128) newChallengeStr = ChallengeStrings(challengeStr=challengeStr) newChallengeStr.save() newPublicKey = addUser(userList[i]['username'], userList[i]['department'], userList[i]['name'], userList[i]['course'], passwords[i]) publicKeys += [newPublicKey] cryptography.permuteList(publicKeys) for i in range(len(publicKeys)): newPublicKey = PublicKeys(publicKey=publicKeys[i]) newPublicKey.save() return passwords