private static void AddMessage(SlackHistoryViewerDbContext dbContext, Message message, string channelId) { var newMessage = new Messages(); newMessage.MessageId = MD5Hasher.GetMd5Hash(message.User + message.TimeStamp); var idUser = dbContext.Users .Where(u => u.UserId == message.User) .Select(u => u.Id) .FirstOrDefault(); if (idUser == 0) { var botId = dbContext.Users .Where(u => u.UserId == AppSettings.Instance.UnknownBotId) .Select(u => u.Id) .FirstOrDefault(); idUser = botId; } newMessage.UserId = idUser; var idChannel = dbContext.Channels .Where(c => c.ChannelId == channelId) .Select(c => c.Id) .FirstOrDefault(); newMessage.ChannelId = idChannel; newMessage.JsonData = JsonConvert.SerializeObject(message); dbContext.Messages.Add(newMessage); }
public Session GenerateSession(long personId, string deviceCode) { var sessionKey = MD5Hasher.GetMd5Hash(Guid.NewGuid().ToString()); var session = new Session(deviceCode, sessionKey, personId, 87360); // 10 Years _apiSessionRepository.Save(session); return(session); }
public ActionResult Login(LoginModel model, string returnUrl) { try { var decodedUrl = ""; if (!string.IsNullOrEmpty(returnUrl)) { decodedUrl = Server.UrlDecode(returnUrl); } var passwordHash = MD5Hasher.GetMd5Hash(model.Username); var password = Encryption.Encrypt(model.Password); var user = _userService.GetUserByCredentials(model.Username, password); if (user != null) { if (passwordHash == user.PasswordHash) { Session["User"] = user; FormsAuthentication.SetAuthCookie(user.Name, false); if (Url.IsLocalUrl(decodedUrl)) { return(Redirect(decodedUrl)); } } else { model.ErrorMessage = "Incorrect combination of email and password, please reenter"; return(View(model)); } } else { model.ErrorMessage = "Incorrect combination of email and password, please reenter"; return(View(model)); } return(View(model)); } catch (Exception e) { Console.WriteLine(e); throw; } }
private void btnLogin_Click(object sender, EventArgs e) { string hash = null; using (MD5 md5Hash = MD5.Create()) hash = MD5Hasher.GetMd5Hash(md5Hash, tbxPassword.Text); string key = null; string serviceUrl = DataManager.baseWebAddress + "services/cloudlogin.php?email=" + tbxEmail.Text + "&password="******"Verbindung zum Cloud-Dienst kann nicht hergestellt werden."); } }
public static void InsertMessagesWithoutDuplicates(IEnumerable <Message> messages, string channelId) { using (var dbContext = new SlackHistoryViewerDbContext()) { foreach (Message message in messages) { var key = message.User + message.TimeStamp; var hash = MD5Hasher.GetMd5Hash(key); if (!CheckDuplicateMessage(dbContext, hash)) { AddMessage(dbContext, message, channelId); } } dbContext.SaveChanges(); } }
public ActionResult Register(RegistrationModel model) { try { var password = EncryptPassword(model.Password); var passwordHash = MD5Hasher.GetMd5Hash(model.Email); var role = _roleService.Get(1); var user = new User { ContactNumber = model.ContactNumber, Email = model.Email, Name = model.FirstName, Surname = model.LastName, CreatedAt = DateTime.Now, ModifiedAt = DateTime.Now, Password = password, PasswordHash = passwordHash }; role.CreatedAt = DateTime.Now; role.ModifiedAt = DateTime.Now; user.AddRole(role); var id = _userService.Save(user); if (id > 0) { return(RedirectToAction("Login", "User")); } } catch (Exception e) { Console.WriteLine(e); throw; } return(View()); }
public static string ToHash(this string value) { return(MD5Hasher.GetMd5Hash(value)); }