Welcome to LQ!!!
Would like to mention that we would not write script for you. Let us know what you have prepared so far?
Did you have a look at passwd man page? If you want to set same password for a user let say testuser you can use:
echo "password" | passwd testuser --stdin
How to use it in script you have to figure out.
If you want to set random password then you might want to have a look at /dev/urandom + tr. The other tools like fold will depend on the number of characters you want in your password.