Ejemplo n.º 1
0
        public bool UpdateUserPassword(string username, string password)
        {
            using (var session = CreateSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    SharpStarUser user = session.Query <SharpStarUser>().SingleOrDefault(p => p.Username.ToLower() == username.ToLower());

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

                    string salt = SharpStarSecurity.GenerateSalt();

                    user.Hash = SharpStarSecurity.GenerateHash(username, password, salt, StarboundConstants.Rounds);
                    user.Salt = salt;

                    session.SaveOrUpdate(user);

                    transaction.Commit();
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override async Task Handle(HandshakeChallengePacket packet, SharpStarClient client)
        {
            if (packet.IsReceive)
            {
                packet.Ignore = true;

                if (client.Server.Player.UserAccount != null || !client.Server.Player.AttemptedLogin || client.Server.Player.Guest)
                {
                    string hash = await Task.Run(() => SharpStarSecurity.GenerateHash("", "", packet.Salt, StarboundConstants.Rounds));

                    await client.Server.ServerClient.SendPacket(new HandshakeResponsePacket { PasswordHash = hash });
                }
                else if (client.Server.Player.AttemptedLogin)
                {
                    await client.Server.ServerClient.SendPacket(new HandshakeResponsePacket { PasswordHash = packet.Salt });
                }
            }

            //SharpStarMain.Instance.PluginManager.CallEvent("handshakeChallenge", packet, client);
        }
Ejemplo n.º 3
0
        public bool AddUser(string username, string password, bool admin = false, int?groupId = null)
        {
            using (var session = CreateSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    SharpStarUser user = session.Query <SharpStarUser>().SingleOrDefault(p => p.Username.ToLower() == username.ToLower());

                    if (user == null)
                    {
                        string salt = SharpStarSecurity.GenerateSalt();

                        SharpStarGroup group = null;
                        if (!groupId.HasValue)
                        {
                            SharpStarGroup defaultGroup = session.Query <SharpStarGroup>().SingleOrDefault(p => p.IsDefaultGroup);

                            if (defaultGroup != null)
                            {
                                group = defaultGroup;
                            }
                        }
                        else
                        {
                            group = session.Query <SharpStarGroup>().SingleOrDefault();
                        }

                        session.Save(new SharpStarUser {
                            Username = username, Hash = SharpStarSecurity.GenerateHash(username, password, salt, 5000), Salt = salt, IsAdmin = admin, Group = group
                        });

                        transaction.Commit();
                    }

                    return(user == null);
                }
            }
        }