Esempio n. 1
0
        public UserRegistrationTableEntity VerifyUserRegistration(string sEmail, string sPassword)
        {
            if (sEmail == null || sPassword == null)
            {
                return(null);
            }

            // get registration row from table
            TableOperation pRegistrationOp     = TableOperation.Retrieve <UserRegistrationTableEntity>("USER", sEmail);
            TableResult    pRegistrationResult = this.Table.Execute(pRegistrationOp);

            if (pRegistrationResult.Result == null)
            {
                return(null);
            }
            UserRegistrationTableEntity pRegistration = (UserRegistrationTableEntity)pRegistrationResult.Result;

            // hash clan passphrase
            string sPassHash = Security.Sha256Hash(sPassword);

            // return if hashes match

            if (sPassHash == pRegistration.Password)
            {
                return(pRegistration);
            }
            return(null);
        }
Esempio n. 2
0
        public string ChangeUserPassword(string sEmail, string sOldPassword, string sNewPassword)
        {
            UserRegistrationTableEntity pUser = VerifyUserRegistration(sEmail, sOldPassword);

            if (pUser == null)
            {
                return(Master.MessagifyError("Incorrect login information"));
            }

            // update the password
            pUser.Password = Security.Sha256Hash(sNewPassword);
            this.Table.Execute(TableOperation.Replace(pUser));

            return(Master.MessagifySimple("Password changed successfully!"));
        }
Esempio n. 3
0
        public string RegisterUser(string sEmail, string sPassword)
        {
            // make sure a user with this email doesn't already exist
            TableOperation pUserRetrieveOp = TableOperation.Retrieve <UserRegistrationTableEntity>("USER", sEmail);

            if (this.Table.Execute(pUserRetrieveOp).Result != null)
            {
                return(Master.MessagifyError("A user with this email already exists."));
            }

            // made it to this point, it's okay to make a new user
            UserRegistrationTableEntity pUser = new UserRegistrationTableEntity(sEmail);

            pUser.Password = Security.Sha256Hash(sPassword);
            pUser.Key      = Master.GenerateKey();
            this.Table.Execute(TableOperation.Insert(pUser));

            XElement pKey   = new XElement("Key", pUser.Key);
            XElement pEmail = new XElement("Email", sEmail);

            return(Master.Messagify("You have successfully registered!", Master.MSGTYPE_BOTH, pKey.ToString() + pEmail.ToString()));
        }
Esempio n. 4
0
        public string ReturningUser(string sEmail, string sPassword)
        {
            UserRegistrationTableEntity pUser = VerifyUserRegistration(sEmail, sPassword);

            if (pUser == null)
            {
                return(Master.MessagifyError("Incorrect login information"));
            }

            // otherwise return them their key and all their clan stubs
            string sKey = pUser.Key;

            XElement pKey   = new XElement("Key", sKey);
            XElement pEmail = new XElement("Email", sEmail);

            // query their email partition key
            TableQuery <RegistrationClanUserTableEntity> pQuery     = new TableQuery <RegistrationClanUserTableEntity>().Where("PartitionKey eq '" + pUser.RowKey + "'");
            List <RegistrationClanUserTableEntity>       lClanInfos = this.Table.ExecuteQuery(pQuery).ToList();

            XElement pClanStubs = new XElement("ClanStubs");

            foreach (RegistrationClanUserTableEntity pClanInfo in lClanInfos)
            {
                string sCombined = pClanInfo.RowKey;

                int    iIndex    = sCombined.IndexOf("|");
                string sClanName = sCombined.Substring(0, iIndex);
                string sUserName = sCombined.Substring(iIndex + 1);

                XElement pClanStub = new XElement("ClanStub");
                pClanStub.SetAttributeValue("ClanName", sClanName);
                pClanStub.SetAttributeValue("UserName", sUserName);
                pClanStubs.Add(pClanStub);
            }

            return(Master.Messagify("Logged in successfully!", Master.MSGTYPE_BOTH, pClanStubs.ToString() + pKey.ToString() + pEmail.ToString()));
        }