Ejemplo n.º 1
0
        internal bool Login(string login, string password)
        {
            UserEntity user = DAO.GetInstance().GetUserByLogin(login);

            if (user == null)
            {
                return(false);
            }

            BLPassword blPassword = new BLPassword();

            if (blPassword.VerifyPassword(password, user.Password))
            {
                byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
                byte[] key  = Guid.NewGuid().ToByteArray();
                Token = Convert.ToBase64String(time.Concat(key).ToArray());

                user.LastConnexion = DateTime.Now;
                user.Token         = Token;
                return(DAO.GetInstance().SaveChanges());
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        internal bool Register(string login, string password, string email, List <string> groups)
        {
            BLPassword blPassword   = new BLPassword();
            string     passwordHash = blPassword.Hash(password);

            // All users are part of the "defaultGroup" so they can have access to services like logout
            groups.Add("defaultGroup");
            List <GroupEntity> groupEntities = DAO.GetInstance().GetGroupsFromListStr(groups);

            UserEntity newUser = new UserEntity
            {
                Login    = login,
                Email    = email,
                Password = passwordHash,
            };

            return(DAO.GetInstance().AddUser(newUser) && DAO.GetInstance().AddUserToGroups(newUser, groupEntities));
        }