This site runs best with JavaScript enabled.

Daily Passwords for Kids' Computer


How I change the logins everyday on the computer to make sure they get their jobs done before zoning out on the computer.

In our home we have an old iMac for the kids to use. They each have their own login. Each login has a parental control that logs them out after one hour. This has been helpful to prevent fights over who has been on too long and limits their screen time.

The problem I've had lately is that we ask them to do homework and chores before getting on the computer, yet they get on anyway.

So I had this idea to change their passwords every day and email the new passwords to my wife and I each morning. This way they we can make sure they have their jobs done before they get on the computer. I know, it sucks to be a nerd's child.

Here is the python script that makes the magic happen...

1#!/usr/bin/env python
2import random
3import smtplib
4
5from subprocess import call
6from email.mime.text import MIMEText
7
8
9FROM_EMAIL = ''
10SMTP_HOST = ''
11SMTP_PORT = 587
12SMTP_USERNAME = ''
13SMTP_PASSWORD = ''
14USE_TLS = True
15TO = ''
16LOGINS = 'child1 child2 child3 etc'.split()
17ADMIN_USERNAME = ''
18ADMIN_PASSWORD = ''
19
20
21passwords = {}
22for login in LOGINS:
23 # get 4 digit random number for the new password
24 password = random.randint(1000, 9999)
25 command = 'dscl -u {0} -P {1} . -passwd /Users/{2} {3}'.format(
26 ADMIN_USERNAME, ADMIN_PASSWORD, login, password)
27 call(command.split())
28 passwords[login] = password
29
30msg = '';
31for key, val in passwords.iteritems():
32 msg += '{0}: {1}\n'.format(key.title(), val)
33msg = MIMEText(msg)
34msg['Subject'] = 'Today\'s passwords';
35msg['From'] = FROM_EMAIL
36msg['To'] = TO
37
38s = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
39s.ehlo()
40if USE_TLS:
41 s.starttls()
42s.login(SMTP_USERNAME, SMTP_PASSWORD)
43s.sendmail(FROM_EMAIL, TO.split(), msg.as_string())
44s.quit()

If you'd like to use this, just enter all the GLOBAL variables at the top. I named this file daily.py and set it to run at 6 am every day with the following crontab setting:

10 6 \* \* \* python /Users/dustin/daily.py

I set up a free account on Mailjet to use as an SMTP server. Thanks Mailjet.

As soon as I ran the script for the first time, my wife got a Gmail notification in the other room and said, "Thank you!" #winning

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter



Dustin Davis