Hi,
Here is a piece of code coming from a project I'm currently working on.
It shows how to generate a hash( md5 or sha-1) and change the password of
the user on the google system.
It's a C# code, you should be able to easily port it to the language of your
choice.
/// <summary>
/// Login in Google System
/// </summary>
internal void Login()
{
service = new AppsService(_Domain, _AdministratorEmail,
_AdministratorPassword);
if (service == null)
throw new Exception("Login Failed");
}
/// <summary>
/// Set ¨Password Hashing function
/// </summary>
/// <param name="hashFunction"></param>
internal void SetHashFunction(string hashFunction)
{
_HashFunction = hashFunction.ToLower();
}
/// <summary>
/// Change Password of user account
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
internal void SetPassword(string userName,string password)
{
//Search the user
UserEntry entry = service.RetrieveUser(userName);
//change the pasword
entry.Login.Password = Hash(password);
entry.Login.HashFunctionName = _HashFunction;
//save modification
entry.Update();
}
private string Hash(string password)
{
if (string.Compare(_HashFunction, "md5") == 0)
{
return CalculateMD5Hash(password);
}
if (string.Compare(_HashFunction, "sha1") == 0)
{
return CalculateSHA1Hash(password);
}
return string.Empty;
}
/// <summary>
/// Hash password using MD5
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private string CalculateMD5Hash(string password)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(password);
bs = md5.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
/// <summary>
/// Hash password using MD5
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private string CalculateSHA1Hash(string password)
{
SHA1CryptoServiceProvider sha1 = new
SHA1CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(password);
bs = sha1.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
Regards,
Emmanuel Dreux
http://www.bcpsoft.fr
2011/2/24 Miq <[email protected]>
> Right now when one of my users forgets their password I make them turn in a
> reset request that verifies they are who they say they are. Once that
> request completes I save the username and new password (new password that I
> specify) into a SQL table. Our admins use a webpage that queries the
> database for resets and we perform the resets manually.
>
> What I am wondering is if there is a way to use an API to reset passwords
> given a username and new password from a text file or csv so I can automate
> the process. I can easily export the existing reset requests on an hourly
> basis into a csv file, I just don't know how to use an API to use my file
> and reset the passwords. I currently use Coldfusion 9 to host the reset
> request page and to write to the SQL backend; so if there is an easier way
> to just integrate the API into the Coldfusion form then that is even better.
>
> Just as fair warning I have never really used APIs before so please assume
> I have no idea what you are talking about if you have a suggestion.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Apps Domain Information and Management APIs" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-apps-mgmt-apis?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google Apps Domain Information and Management APIs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-apps-mgmt-apis?hl=en.