Esempio n. 1
0
        public Guid Create(string userName, string password)
        {
            if ((String.IsNullOrWhiteSpace(userName)) || (String.IsNullOrWhiteSpace(password)))
            {
                return(Guid.Empty);
            }

            var passwordInformation = _passwordHash.CreatePasswordInformation(Encoding.UTF8.GetBytes(password));

            var dbUser = new DbUser
            {
                Id           = Guid.NewGuid(),
                Iterations   = passwordInformation.Iterations,
                Password     = passwordInformation.Hash,
                Salt         = passwordInformation.Salt,
                UserName     = userName,
                CreationDate = DateTime.Now,
            };

            using (var context = new RelayContext())
            {
                context.Users.Add(dbUser);
                context.SaveChanges();

                return(dbUser.Id);
            }
        }
Esempio n. 2
0
        public CreateLinkResult CreateLink(string symbolicName, string userName)
        {
            using (var context = new RelayContext())
            {
                var password            = _passwordHash.GeneratePassword(_configuration.LinkPasswordLength);
                var passwordInformation = _passwordHash.CreatePasswordInformation(password);

                var link = new DbLink
                {
                    Id           = Guid.NewGuid(),
                    Password     = passwordInformation.Hash,
                    Salt         = passwordInformation.Salt,
                    Iterations   = passwordInformation.Iterations,
                    SymbolicName = symbolicName,
                    UserName     = userName,
                    CreationDate = DateTime.UtcNow
                };

                context.Links.Add(link);
                context.SaveChanges();

                var result = new CreateLinkResult
                {
                    Id       = link.Id,
                    Password = Convert.ToBase64String(password)
                };

                return(result);
            }
        }