[PoC] Password protected configs


  • Admin

    NOTE: There is a bug that allows to use incorrect passwords. I will fix it when I have some time, so for now do not use this method ^_^

    This method will be effective only if your modded version of OpenBullet supports encrypted config formats or if you pull them from the API without giving the user the ability to edit them.

    This will require the user to enter a password that is stored inside a text file after the first time it's set so the user does not need to add it anymore.

    First of all add an input to the config (Other Options) with the variable name INPUTPASS

    PoC code with 1 file per config:

    ## If the config password was already set, go to start
    IF "<CONFIGPASSWORD>" EqualTo "MySecretPassword"
    JUMP #START
    ENDIF
    
    SET VAR "ConfigFile" "MyConfigPassword.txt"
    
    ## If this fails, the variable is not created
    UTILITY File "<ConfigFile>" Read -> VAR "CFGPWD" 
    
    ## If the above file does not exist
    IF "<CFGPWD>" DoesNotExist
    ## Set the user input password as global password
    SET NEWGVAR "CONFIGPASSWORD" "<INPUTPASS>"
    ## Write it to the file for future use
    UTILITY File "<ConfigFile>" Write "<INPUTPASS>"
    ELSE
    ## Otherwise use the password you just read from file
    SET NEWGVAR "CONFIGPASSWORD" "<CFGPWD>"
    ENDIF
    
    ## Actual start of the config
    #START FUNCTION Constant "Start of the config"
    

    PoC code with 1 file per multiple configs:

    ## If the config password was already set, go to start
    IF "<CONFIGPASSWORD>" EqualTo "MySecretPassword"
    JUMP #START
    ENDIF
    
    SET VAR "ConfigName" "MyExampleConfig"
    SET VAR "ConfigFile" "ConfigPasswords.txt"
    
    ## If this fails, the variable is not created
    UTILITY File "<ConfigFile>" ReadLines -> VAR "CFGPWDS" 
    
    ## If the above file does not exist
    IF "<CFGPWDS>" DoesNotExist
    ## Set the user input password as global password
    SET NEWGVAR "CONFIGPASSWORD" "<INPUTPASS>"
    ## Create the file and write the first line
    UTILITY File "<ConfigFile>" WriteLines "<ConfigName>:<INPUTPASS>"
    ELSE
    ## Otherwise check if the file contains the password
    ## First we split the lines into a dictionary
    FUNCTION RegexMatch "^[^:]*" "<CFGPWDS[*]>" -> VAR "CFGNAMES"
    FUNCTION Replace "^[^:]*:" "" UseRegex=True "<CFGPWDS[*]>" -> VAR "CFGPASSES"
    UTILITY List "CFGNAMES" Map "CFGPASSES" -> VAR "DIC"
    ## If the dictionary key exists
    IF "<CFGNAMES>" Contains "<ConfigName>"
    SET NEWGVAR "CONFIGPASSWORD" "<DIC(<ConfigName>)>"
    ELSE
    ## Otherwise append it to file too
    UTILITY File "<ConfigFile>" AppendLines "<ConfigName>:<INPUTPASS>"
    ENDIF
    
    ## Actual start of the config
    #START FUNCTION Constant "Start of the config"
    

    I did not test this thoroughly so if you find any bugs or a better way to do it feel free to reply below.


Log in to reply