Example #1
0
        public static string RegisterNewUser(tbl_userdata user)
        {
            string activationCode = generateActivationCode();

            try
            {
                Dictionary <string, Object> dic = new Dictionary <string, Object>();
                dic.Add("in_userName", user.fld_username);
                dic.Add("in_password", SaltNHash(user.fld_password));
                dic.Add("in_firstName", user.fld_firstname);
                dic.Add("in_lastName", user.fld_lastname);
                dic.Add("in_gender", user.fld_gender);
                dic.Add("in_address", user.fld_address);
                dic.Add("in_zipCode", user.fld_zipcode);
                dic.Add("in_dob", user.fld_dateofbirth);
                dic.Add("in_phoneNumber", user.fld_phonenumber);
                dic.Add("in_emailAddress", user.fld_email);
                dic.Add("in_activationCode", activationCode);
                dic.Add("in_isActivated", false);
                dic.Add("out_userId", 0);
                dic = ProcedureCall <int> .ExecuteNonQuery(dic, "user_Register");

                user.fld_activationcode = activationCode;
                user.fld_userid         = Convert.ToInt32(dic["out_userId"]);
                EsUpdater <tbl_userdata> .InsertDocument(user, "moll_users", "User", dic["out_userId"].ToString());

                return(activationCode);
            }
            catch (Exception e)
            {
                return("Db Error!");
            }
        }
Example #2
0
        public static tbl_userdata FindUserByEmail(string emailAddress)
        {
            tbl_userdata foundUser          = new tbl_userdata();
            Dictionary <string, Object> dic = new Dictionary <string, Object>();

            dic.Add("in_email", emailAddress);
            foundUser = (tbl_userdata)ProcedureCall <tbl_userdata> .ExecuteReader(dic, "FindUserByEmail");

            return(foundUser);
        }
Example #3
0
        public static tbl_userdata FindUserById(int userId)
        {
            tbl_userdata foundUser          = new tbl_userdata();
            Dictionary <string, Object> dic = new Dictionary <string, Object>();

            dic.Add("in_givenUserId", userId);
            foundUser = (tbl_userdata)ProcedureCall <tbl_userdata> .ExecuteReader(dic, "FindUserById");

            return(foundUser);
        }
Example #4
0
        public static LoginModel UserLogin(LoginModel loginMdl)
        {
            //Check if user is found (return the password)
            Dictionary <string, Object> dic1 = new Dictionary <string, object>();

            dic1.Add("in_emailAddress", loginMdl.EmailAddress);
            tbl_userdata user = ProcedureCall <tbl_userdata> .ExecuteReader(dic1, "auth_CheckUserExistsLogin");

            string result = user.fld_password;

            if (result == null)
            {
                //Account was not found
                loginMdl.UserId = -1;
                return(loginMdl);
            }


            //Check if passwords match

            //First we convert the storedPassword to bytes
            if (result != null)
            {
                string storedPassword = result.ToString();

                byte[] passwordBytes = Convert.FromBase64String(storedPassword);

                //We grab the salt
                byte[] salt = new byte[16];
                Array.Copy(passwordBytes, 0, salt, 0, 16);

                //Hash the given password and grab the resulting hash
                Rfc2898DeriveBytes pbkdf2    = new Rfc2898DeriveBytes(loginMdl.Password, salt, 10000);
                byte[]             givenHash = pbkdf2.GetBytes(20);

                //Compare the hashes of the stored password with the given password
                int success = 1;
                for (int i = 0; i < 20; i++)
                {
                    if (passwordBytes[i + 16] != givenHash[i])
                    {
                        loginMdl.UserId = 0;
                        return(loginMdl);
                    }
                }
            }


            //Lastly, we check if the account is verified. If it is, the procedure will return all relevant information for later usage

            if (user.fld_isactivated == 0)
            {
                loginMdl.UserId   = -3;
                loginMdl.UserName = user.fld_username;
                return(loginMdl);
            }


            loginMdl.Admin        = user.fld_adminPriv;
            loginMdl.UserName     = user.fld_username;
            loginMdl.EmailAddress = user.fld_email;
            loginMdl.UserId       = user.fld_userid;

            return(loginMdl);
            //Retrieve relevant info
        }