Daily Passwords for Kids' Computer
Photo by marcos mayer on Unsplash
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 python2import random3import smtplib45from subprocess import call6from email.mime.text import MIMEText789FROM_EMAIL = ''10SMTP_HOST = ''11SMTP_PORT = 58712SMTP_USERNAME = ''13SMTP_PASSWORD = ''14USE_TLS = True15TO = ''16LOGINS = 'child1 child2 child3 etc'.split()17ADMIN_USERNAME = ''18ADMIN_PASSWORD = ''192021passwords = {}22for login in LOGINS:23 # get 4 digit random number for the new password24 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] = password2930msg = '';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_EMAIL36msg['To'] = TO3738s = 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