Sample code:
List<User> u = new List<User>();
List<Id> ids = new List<Id>();
String test = ‘test’;
u = Database.Query(‘SELECT Id, Name FROM User WHERE Name =: test’);
System.debug(‘User details are ‘ + u);
for(User usr : u)
{
System.resetPassword(usr.Id,true);
}