private async void Login() { if (string.IsNullOrEmpty(CPF) || string.IsNullOrEmpty(Password)) { await Application.Current.MainPage.DisplayAlert("Há Valores Vazios", "Por favor, verifique se todos os campos estão preenchidos.", "OK"); } else { MD5Helper md5 = new MD5Helper(); LoginModel login = new LoginModel { cpf = new string(CPF.Where(char.IsDigit).ToArray()), senha = md5.CreateMD5(Password) }; LoginResponse loginResponse = await _restService.LogUserIn(login); if (loginResponse.StatusCode == 200) { Barrel.Current.Add(Constants.USER_KEY, loginResponse.Key, TimeSpan.Zero); Barrel.Current.Add(Constants.USER_CPF, new string(CPF.Where(char.IsDigit).ToArray()), TimeSpan.Zero); await Application.Current.MainPage.Navigation.PushAsync(new ClientPage()); } else { await Application.Current.MainPage.DisplayAlert("Falha no login.", loginResponse.Message, "OK"); } } }
private async void Signup() { if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(CPF) || string.IsNullOrEmpty(Birthday) || string.IsNullOrEmpty(Password)) { await Application.Current.MainPage.DisplayAlert("Há Valores Vazios", "Por favor, verifique se todos os campos estão preenchidos.", "OK"); } else { MD5Helper md5 = new MD5Helper(); UserModel user = new UserModel { nome = Name, cpf = new string(CPF.Where(char.IsDigit).ToArray()), nascimento = DateTimeOffset.Parse(Birthday).ToString("s"), senha = md5.CreateMD5(Password) }; LoginResponse signupResponse = await _restService.SignUserUp(user); if (signupResponse.StatusCode == 200) { await Application.Current.MainPage.DisplayAlert("Sucesso!", "Cadastro bem-sucedido.", "OK"); await Application.Current.MainPage.Navigation.PopAsync(); } else { await Application.Current.MainPage.DisplayAlert("Falha no login.", signupResponse.Message, "OK"); } } }
private static bool CheckUpdatePackageMD5(string filePath, string md5Code, out MD5Helper.FileMD5ErrorMode errCode) { string currentMD5Code; errCode = MD5Helper.CreateMD5(filePath, out currentMD5Code); if (errCode != MD5Helper.FileMD5ErrorMode.OK) { System.Console.WriteLine("Calculation file md5 error,Err:" + errCode.ToString()); try { File.Delete(filePath); } catch { } return(false); } if (md5Code.ToLower() != currentMD5Code.ToLower()) { System.Console.WriteLine("File md5 is not match!"); try { File.Delete(filePath); } catch { } return(false); } else { return(true); } }
public IHttpActionResult Post(User model) { AjaxStringResult result = new AjaxStringResult(); model.Password = MD5Helper.CreateMD5(model.Password); _UserDAL.Add(model); result.data = "保存成功"; return(Json(result)); }
private void LoginUser() { if (!String.IsNullOrEmpty(Login) && !String.IsNullOrEmpty(Password)) { if (DbManager.LoginUser(Login, MD5Helper.CreateMD5(Password))) { RaiseLoginCompleted(); return; } } MessageBox.Show("Niepoprawny użytkownik lub hasło!"); }
/// <summary> /// 校验更新包MD5码 /// </summary> /// <param name="filePath"></param> /// <param name="md5Code"></param> /// <param name="errCode"></param> /// <returns>是否校验成功</returns> private static bool FileMD5Check(string filePath, string md5Code, out MD5Helper.FileMD5ErrorMode errCode) { string currentMD5Code; errCode = MD5Helper.CreateMD5(filePath, out currentMD5Code); if (errCode != MD5Helper.FileMD5ErrorMode.OK) { System.Console.WriteLine("Calculation file md5 error,Err:" + errCode.ToString()); if (_sw != null) { _sw.WriteLine("(UTC:" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "): Calculation file md5 error,Err:" + errCode.ToString()); } try { File.Delete(filePath); } catch { } return(false); } if (md5Code.ToLower() != currentMD5Code.ToLower()) { System.Console.WriteLine("File md5 is not match!"); if (_sw != null) { _sw.WriteLine("(UTC:" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "): File md5 is not match!"); } try { File.Delete(filePath); } catch { } return(false); } else { return(true); } }
public IHttpActionResult Login([FromBody] LoginForm loginForm) { AjaxResult <LoginInfo> result = new AjaxResult <LoginInfo>(); string md5Password = MD5Helper.CreateMD5(loginForm.password); User user = userDAL.Get().FirstOrDefault(o => o.LoginName == loginForm.username && o.Password == md5Password); if (user != null) { user.Password = ""; // 将密码隐藏 string userData = JsonHelper.JsonSerialize(user); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, loginForm.username, DateTime.Now, DateTime.Now.AddDays(1), true, userData); LoginInfo data = new LoginInfo() { token = FormsAuthentication.Encrypt(ticket), user = user }; result.data = data; } else { result.state = false; result.error = "用户登陆校验失败!"; } return(Json(result)); }
public IHttpActionResult change([FromBody] dynamic password) { AjaxStringResult result = new AjaxStringResult(); User user = CommonHelper.User; string oldPassword = MD5Helper.CreateMD5(password.txtOld.ToString()); if (!string.IsNullOrWhiteSpace(oldPassword)) { if (_UserDAL.IsExist(o => o.Id == user.Id && o.Password == oldPassword)) { if (!string.IsNullOrWhiteSpace(password.txtNew.ToString())) { user.Password = MD5Helper.CreateMD5(password.txtNew.ToString()); _UserDAL.changePassword(user); result.data = "密码修改成功!"; } else { result.state = false; result.error = "新密码不能为空!"; } } else { result.state = false; result.error = "原密码校验失败!"; } } else { result.state = false; result.error = "原密码不能为空!"; } return(Json(result)); }
public static bool IsMD5Equal(string firstFileName, string secondFileName) { string firstMD5 = ""; MD5Helper.FileMD5ErrorMode errorMode = MD5Helper.CreateMD5(firstFileName, out firstMD5); if (errorMode != MD5Helper.FileMD5ErrorMode.OK) { return(false); } string secondMD5 = ""; errorMode = MD5Helper.CreateMD5(secondFileName, out secondMD5); if (errorMode != MD5Helper.FileMD5ErrorMode.OK) { return(false); } if (firstMD5 != secondMD5) { return(false); } return(true); }
public async Task <UploadFileResult> UploadFileWithJsonMetadata(string filePath, string metadataJson, string fileMimeType, string phaidraType) { UploadFileResult result = new UploadFileResult(); result.Success = false; string restMethod = phaidraType + CONST_Rest_create; //string fileMimeType = "image/png"; //string metadataMimeType = "application/octet-stream"; string multipartMimeType = "application/octet-stream"; try { FileInfo fileFI = new FileInfo(filePath); string md5Checksum = MD5Helper.CreateMD5(filePath); var fileContent = new StreamContent(fileFI.OpenRead()) { Headers = { ContentType = new MediaTypeHeaderValue(multipartMimeType) } }; fileContent.Headers.Add("Content-Disposition", string.Format("form-data; name=\"file\"; filename=\"file{0}\"", System.IO.Path.GetExtension(fileFI.Name))); var formDataContent = new MultipartFormDataContent(); formDataContent.Add(fileContent, "file", fileFI.Name); AddStringContent(formDataContent, "metadata", metadataJson); AddStringContent(formDataContent, "mimetype", fileMimeType); AddStringContent(formDataContent, "checksumtype", "MD5"); AddStringContent(formDataContent, "checksum", md5Checksum); var client = GetClient(auth: true); client.DefaultRequestHeaders.Add("Expect", "100-continue"); using (var res = await client.PostAsync(GetRequestUrl(restMethod), formDataContent)) { string responseJson = await res.Content.ReadAsStringAsync(); result.Success = res.IsSuccessStatusCode; JObject response = (JObject)JsonConvert.DeserializeObject(responseJson); result.Status = (long)((JValue)response.SelectToken("status")).Value; if (result.Status == 200) { string pid = (string)((JValue)response.SelectToken("pid")).Value; result.CreatedPid = pid; } else { Logger.LogE($"Success is false in UploadFileWithJsonMetadata."); Logger.LogE($"Request: {metadataJson}"); Logger.LogE($"Response: {responseJson}"); } } } catch (Exception ex) { Logger.LogE($"Error in UploadFileWithJsonMetadata: {ex.ToString()}"); Debug.WriteLine(ex.ToString()); result.Success = false; return(result); } return(result); }
private string MakeCacheFileName(Uri uri) => $"{MD5Helper.CreateMD5(uri.ToString())}.{CACHE_FILE_EXT}";
public void Test_MD5Hash(string source, string expected) { var md5result = MD5Helper.CreateMD5(source); Assert.AreEqual(expected, md5result); }