Fix up password enforcement code

@chrisndodge, I tried to improve the code in your password enforcement pull request (#2312). Can you take a look? (cc @antoviaque @ormsbee @jzoldak)