//現在のクリアデータを、外部にセーブする // public static void Save() { string json = JsonUtility.ToJson(SaveData.Instance); string iv; string base64; MyCryptography.Encrypt(json, out iv, out base64); byte[] ivBytes = Encoding.UTF8.GetBytes(iv); byte[] base64Bytes = Encoding.UTF8.GetBytes(base64); using (FileStream fs = new FileStream(GetSaveFilePath(), FileMode.Create, FileAccess.Write)) { using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(ivBytes.Length); bw.Write(ivBytes); bw.Write(base64Bytes.Length); bw.Write(base64Bytes); } } }
/// <summary> /// Validates context /// </summary> /// <param name="context">Context</param> /// <returns>Validation task.</returns> public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { try { // getting user var user = await this._userRepository.FindAsync(context.UserName); // checking password if (user != null) { // if password is ok set if (user.Password == MyCryptography.Encrypt(context.Password) && user.IsVerified == true) // { context.Result = new GrantValidationResult( subject: user.Id.ToString(), authenticationMethod: "custom", claims: GetUserClaims(user)); return; } // othwerwise construct error response context.Result = new GrantValidationResult( TokenRequestErrors.InvalidGrant, "Incorrect password or user is not verified"); return; } // message about non-existing user context.Result = new GrantValidationResult( TokenRequestErrors.InvalidGrant, "User does not exist."); return; } // catching exception catch (Exception) { context.Result = new GrantValidationResult( TokenRequestErrors.InvalidGrant, "Invalid username or password"); } }
/// <summary> /// Init The buffer to store the login user infomation at the client side. /// /// UserGuid : After successfully server-side logined, get this value. /// /// RoleName, LoginName: Got from user input at the login form or dcom login call /// /// The user inputed plain password is encrypted and stored here, encrypted is for Security net-work transfer. /// /// ClientSessionID is a random string to encrypt and decrypt the password transfer between server and client Side /// ///Para: different bit stand for different meanings ///It's Value is set by WebserviceManager to storage the status got from server side ///0bit: no meanings ///1bit: no meanings ///2bit: 1 for no hard Dog pluged at the IIS Server Machine ///3bit: 1 fot the server time has exceed the the expire-time recorded at the hard dog, /// /// FunsLicensedStr: stored the License function string recorded in the hard dog,got after successfully logined /// /// IP: Client side IP Address, is for judging whether the calling is from the same client machine. /// /// </summary> /// <returns></returns> public UserRow NewNullRow() { UserRow newRow = this.User.NewUserRow(); //UserGuid : After successfully server-side logined, get this value. newRow.UserGuid = ""; //RoleName, LoginName: Got from user input at the login form or dcom login call newRow.RoleName = ""; newRow.LoginName = ""; newRow.LocalName = ""; //The user inputed plain password is encrypted and stored here, encrypted is for Security net-work transfer. newRow.PasswordEncrypted = ""; //ClientSessionID is a random string to encrypt and decrypt the password transfer between server and client Side MyCryptography c = new MyCryptography("GCRIS2-20061025"); newRow.ClientSessionID = c.Encrypt(DateTime.Now.ToLongTimeString());// FormsAuthentication.HashPasswordForStoringInConfigFile(DateTime.Now.ToLongTimeString(), "SHA1"); //Para: different bit stand for different meanings //It's Value is set by WebserviceManager to storage the status got from server side //0bit: no meanings //1bit: no meanings //2bit: 1 for no hard Dog plugs at the IIS Server Machine //3bit: 1 for the server time has exceed the the expire-time recorded at the hard dog newRow.Para = 0; //Para: different bit stand for different meanings //It's Value is set by client to storage the status got from client side //0bit: 1 for web clinic and 0 for smart client //1bit: no meanings //2bit: no meanings //3bit: no meanings newRow.ClientPara = 0; //FunsLicensedStr: stored the License function string recorded in the hard dog, got after successfully logined newRow.FunsLicensedStr = ""; //ServerTime: IIS Server side time got after successfully logined newRow.ServerTime = System.DateTime.MinValue; string strHostName = Dns.GetHostName(); IPHostEntry IPList = Dns.GetHostEntry(strHostName); string strIPAddress = ""; foreach (IPAddress ip in IPList.AddressList) { strIPAddress = ip.ToString(); } //IP: Client side IP Address, is for judging whether the calling is from the same client machine. newRow.IP = strIPAddress; #region Added by Blue for RC507 - US16220, 07/14/2014 //get client side MAC address string mac = string.Empty; ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if (mo["IPEnabled"].ToString() == "True") { mac = mo["MacAddress"].ToString(); } } newRow.IP = string.Format("{0}&{1}&{2}", newRow.IP, mac, strHostName); #endregion this.User.AddUserRow(newRow); return(newRow); }
public async Task <IActionResult> Put(int id, [FromBody] AdminInfo admin) { var userName = GetCurrentUserName(); if (userName == "Admin888") { await this.repo.ExecuteOperationAsync("UpdateAdmin", new[] { new KeyValuePair <string, object>("id", id), new KeyValuePair <string, object>("name", admin.Name ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("email", admin.Email ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("password", MyCryptography.Encrypt(admin.Password) ?? DBNull.Value.ToString()) }); return(Ok(await this.repo.ExecuteOperationAsync("GetAdmin", new[] { new KeyValuePair <string, object>("id", id) }))); } return(NotFound()); }
public async Task <IActionResult> Post([FromBody] AdminInfo admin) { var userName = GetCurrentUserName(); if (userName == "Admin888") //our super admin { if ((int)this.userRepo.ExecuteOperation("ExistsLogin", new[] { new KeyValuePair <string, object>("login", admin.Login) }) == 1) { throw new System.Exception("Username already exists"); } var res = await this.repo.ExecuteOperationAsync("CreateAdmin", new[] { new KeyValuePair <string, object>("name", admin.Name), new KeyValuePair <string, object>("email", admin.Email), new KeyValuePair <string, object>("login", admin.Login), new KeyValuePair <string, object>("password", MyCryptography.Encrypt(admin.Password)) }); return(Ok(res)); } return(NotFound()); }
public async Task <IActionResult> Put(int id, [FromBody] SellerInfo seller) { var userId = GetCurrentUserId(); if (userId == ((SellerInfo)(await this.repo.ExecuteOperationAsync("GetSeller", new[] { new KeyValuePair <string, object>("id", id) }))).UserId) { await this.repo.ExecuteOperationAsync("UpdateSeller", new[] { new KeyValuePair <string, object>("id", id), new KeyValuePair <string, object>("name", seller.Name ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("cellphone", seller.CellPhone ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("address", seller.Address ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("email", seller.Email ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("password", MyCryptography.Encrypt(seller.Password) ?? DBNull.Value.ToString()) }); return(await this.GetById(id)); } return(NotFound()); }
public async Task <IActionResult> Post([FromBody] SellerInfo seller) { if ((int)this.userRepo.ExecuteOperation("ExistsLogin", new[] { new KeyValuePair <string, object>("login", seller.Login) }) == 1) { throw new System.Exception("Username already exists"); } var res = await this.repo.ExecuteOperationAsync("CreateSeller", new[] { new KeyValuePair <string, object>("name", seller.Name), new KeyValuePair <string, object>("email", seller.Email), new KeyValuePair <string, object>("cellphone", seller.CellPhone), new KeyValuePair <string, object>("address", seller.Address), new KeyValuePair <string, object>("login", seller.Login), new KeyValuePair <string, object>("password", MyCryptography.Encrypt(seller.Password)) }); return(Ok(res)); }
public async Task <IActionResult> Put(int id, [FromBody] CustomerInfo customer) { var userId = GetCurrentUserId(); if (((CustomerInfo)(await this.repo.ExecuteOperationAsync("GetCustomer", new[] { new KeyValuePair <string, object>("id", id) }))).UserId == userId) { await this.repo.ExecuteOperationAsync("UpdateCustomer", new[] { new KeyValuePair <string, object>("id", id), new KeyValuePair <string, object>("name", customer.Name = customer.Name ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("surname", customer.Surname = customer.Surname ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("email", customer.Email = customer.Email ?? DBNull.Value.ToString()), new KeyValuePair <string, object>("password", customer.Password = MyCryptography.Encrypt(customer.Password) ?? DBNull.Value.ToString()) }); return(Ok(await this.Get(id))); } return(NotFound()); }