Another little snippet recipe for those interested.
If you are using auth branch you have probably noticed that the only function to change a password is the Client side
[Client] Meteor.changePassword(oldPassword, newPassword, callback)callback: Function(error|null)- Must be logged in to call this. Changes the currently logged in user.
May application has Group controller Resource ACL. So there is an Administrators group, which can manage Groups, Group Permissions and Users (and which groups they belong to and inherit Group ACL Permissions from).
I needed my Administrators group to have the ability to create users, edit/update and of course change passwords.
So, I whipped up this for the change password part. Clearly unofficial.
1. I put this in my server side Meteor.users.allow({}); for insert. Caveat, if you aren't locking down your server side inserts, updates and removes with either checking the logged in user or using some kind of Group ACL you better otherwise this snippet will create a security breach and you don't want any OWASP violations.
2. So, in my insert, locked down through my security stuff I do this.
//always set server side update time/date stamp cuz users/clients can't be trusted
var ts = new Date();
modifier.$set.updated = ts;
//special case for password change
if(modifier.$set){ //make sure this is a $set
if(modifier.$set.password){ //make sure this is a password $set
var services = {};
services.password = {};
services.password.srp = Meteor._srp.generateVerifier( modifier.$set.password );
modifier.$set.services = services;
fields.splice(fields.indexOf("password"),1);
fields.push('services');
delete modifier.$set.password; //remove password
}
}
return true;
I tested it on a half dozen user records with login under PasswordA, Admin changes to PasswordB, users log out and then cannot login with PasswordA but requires PasswordB...dozens of times. Also checked Mongodb records as well.
Yes, it is hackety hackety but it does follow the lead of the auth branch core code for usage of the srp stuff. I didn't do this as a PR on auth branch yet. It seems business use case specific. Two cents? Business use case or should this be a server side feature on auth branch? Maybe this discussion belongs in Meteor core, but since it is a recipe I thought it deserved to be in Meteor talk.
Enjoy.........
Steeve