Example #1
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);
            }
        }