diff --git a/ClientServerLib/ClientServerLib/CServer.cs b/ClientServerLib/ClientServerLib/CServer.cs index d2ef677d..4a58cdba 100644 --- a/ClientServerLib/ClientServerLib/CServer.cs +++ b/ClientServerLib/ClientServerLib/CServer.cs @@ -168,13 +168,6 @@ namespace ServerLib #region user management - private static SetPasswordDelegate _SetPassword; - public static SetPasswordDelegate SetPassword - { - internal get { return CServer._SetPassword; } - set { CServer._SetPassword = value; } - } - private static ValidatePasswordDelegate _ValidatePassword; public static ValidatePasswordDelegate ValidatePassword { diff --git a/ClientServerLib/ClientServerLib/CWebservice.cs b/ClientServerLib/ClientServerLib/CWebservice.cs index 7570e39b..8c6f9302 100644 --- a/ClientServerLib/ClientServerLib/CWebservice.cs +++ b/ClientServerLib/ClientServerLib/CWebservice.cs @@ -81,7 +81,8 @@ namespace ServerLib if (profile.ProfileId != -1) //-1 is the id for a new profile { - if (!(_CheckRight(EUserRights.EditAllProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profile.ProfileId)) + if (!(_CheckRight(EUserRights.EditAllProfiles) + || CSessionControl.GetUserIdFromSession(sessionKey) == profile.ProfileId)) { return; } @@ -97,17 +98,6 @@ namespace ServerLib return; } - if (!string.IsNullOrEmpty(profile.Password)) - { - int profileId = profile.ProfileId; - if (profileId == -1) - { - profileId = CServer.GetUserIdFromUsername(profile.PlayerName); - } - - CServer.SetPassword(profileId, profile.Password); - } - CServer.SendProfileData(profile); } diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 879fcb4d..d8b8bbb8 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -205,7 +205,7 @@ namespace Vocaluxe.Base.Server newProfile.Avatar = _AddAvatar(profile.Avatar); } - else if (newProfile.Avatar == null) + else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1) { newProfile.Avatar = CProfiles.GetAvatars().First(); @@ -234,6 +234,26 @@ namespace Vocaluxe.Base.Server newProfile.GuestProfile = (EOffOn)profile.Type; } + if (!string.IsNullOrEmpty(profile.Password)) + { + if (profile.Password == "***__CLEAR_PASSWORD__***") + { + newProfile.PasswordSalt = null; + newProfile.PasswordHash = null; + } + else + { + RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); + byte[] buffer = new byte[128]; + rng.GetNonZeroBytes(buffer); + byte[] salt = buffer; + byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(profile.Password), salt); + + newProfile.PasswordSalt = salt; + newProfile.PasswordHash = hashedPassword; + } + } + if (existingProfile != null) { CProfiles.EditProfile(newProfile); @@ -588,23 +608,6 @@ namespace Vocaluxe.Base.Server #region user management - private static void _SetPassword(int profileId, string newPassword) - { - CProfile profile = CProfiles.GetProfile(profileId); - if (profile == null) - { - throw new ArgumentException("Invalid profileId"); - } - - RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); - byte[] buffer = new byte[128]; - rng.GetNonZeroBytes(buffer); - byte[] salt = buffer; - byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(newPassword), salt); - - profile.PasswordSalt = salt; - profile.PasswordHash = hashedPassword; - } private static bool _ValidatePassword(int profileId, string password) { diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index 15ffb8ae..8184e184 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -57,14 +57,22 @@ function initPageLoadHandler() { dataToUpload["Type"] = $('#playerType').prop("value"); dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value"); dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null; - dataToUpload["Password"] = $('#playerPassword').prop("value") != "**oldPassword**" ? $('#playerPassword').prop("value") : null; + var pass = $('#playerPassword').prop("value"); + if (pass != "***__oldPassword__***") { + if (pass == "") { + dataToUpload["Password"] = "***__CLEAR_PASSWORD__***"; + } else { + dataToUpload["Password"] = pass; + } + } else { + dataToUpload["Password"] = null; + } + request({ url: "sendProfile", - dataType: "json", contentType: "application/json;charset=utf-8", type: "POST", - headers: { "session": sessionId }, data: JSON.stringify(dataToUpload), }, "Uploading profile...").done(function () { history.back(); @@ -97,14 +105,22 @@ function initPageLoadHandler() { dataToUpload["Type"] = $('#playerType').prop("value"); dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value"); dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null; - dataToUpload["Password"] = $('#playerPassword').prop("value") != "**oldPassword**" ? $('#playerPassword').prop("value") : null; + var pass = $('#playerPassword').prop("value"); + if (pass != "***__oldPassword__***") { + if (pass == "") { + dataToUpload["Password"] = "***__CLEAR_PASSWORD__***"; + } else { + dataToUpload["Password"] = pass; + } + } else { + dataToUpload["Password"] = null; + } + request({ url: "sendProfile", - dataType: "json", contentType: "application/json;charset=utf-8", type: "POST", - headers: { "session": sessionId }, data: JSON.stringify(dataToUpload) }, 'Creating profile...').done(function () { $.mobile.changePage("#login", { transition: "slidefade" }); @@ -120,15 +136,15 @@ function initPageLoadHandler() { addImage($('#playerAvatar')[0], data.Avatar, "img/profile.png"); $('#playerAvatar').data("changed", false); - $('#playerType').prop("value", data.Type); - $('#playerDifficulty').prop("value", data.Difficulty); + $('#playerType').prop("selectedIndex", data.Type).selectmenu("refresh"); + $('#playerDifficulty').prop("selectedIndex", data.Difficulty).selectmenu("refresh"); if (data.IsEditable) { $('#playerName').prop('disabled', false); $('#playerType').prop('disabled', false); $('#playerDifficulty').prop('disabled', false); $('#playerSaveButton').show().unbind("click"); $('#playerAvatar').unbind("click"); - $('#playerPassword').prop('disabled', false).parent().show(); + $('#playerPassword').prop('disabled', false).prop("value", "***__oldPassword__***").parent().show(); $('#playerPasswordLabel').show(); $('#playerAvatar').click(function () { @@ -736,7 +752,6 @@ function initMainPageHandler() { reader.onloadend = function (e) { request({ url: "sendPhoto", - dataType: "json", contentType: "application/json;charset=utf-8", type: "POST", headers: { "session": sessionId },