/// <summary> /// Change a user's password. /// </summary> /// <param name="username">The username.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> /// <param name="role">The role: DJ or Mobile</param> /// <returns>The outcome of the operation.</returns> public Response ChangePassword(int ID, string role, string newPassword) { Response r = new Response(); if (!role.Equals("DJ") && !role.Equals("Mobile")) { r.error = true; r.message = "Bad role"; return r; } using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection r = db.OpenConnection(); if (r.error) return r; // Get the salt from the database and salt/hash the password. string salt = Common.CreateSalt(16); if (role == "DJ") r = db.DJSetSalt(ID, salt); else r = db.MobileSetSalt(ID, salt); if (r.error) return r; string saltHashPassword = Common.CreatePasswordHash(newPassword, salt); if (role == "DJ") r = db.DJSetPassword(ID, saltHashPassword); else r = db.MobileSetPassword(ID, saltHashPassword); if (r.error) return r; return r; } }
/// <summary> /// Change a user's password. /// </summary> /// <param name="username">The username.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> /// <param name="role">The role: DJ or Mobile</param> /// <returns>The outcome of the operation.</returns> public Response ChangePassword(int ID, string role, string newPassword) { ExpResponse r = new ExpResponse(); if (!role.Equals("DJ") && !role.Equals("Mobile")) { r.setErMsgStk(true, "Bad Role Given", Environment.StackTrace); return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); } using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection r = db.OpenConnection(); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); // Get the salt from the database and salt/hash the password. string salt = Common.CreateSalt(16); if (role == "DJ") r = db.DJSetSalt(ID, salt); else r = db.MobileSetSalt(ID, salt); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_CRED_WRONG, Common.LogFile.Web); string saltHashPassword = Common.CreatePasswordHash(newPassword, salt); if (role == "DJ") r = db.DJSetPassword(ID, saltHashPassword); else r = db.MobileSetPassword(ID, saltHashPassword); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); return r; } }