[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.


  • Banned

    waiting for this to be fixed @Ruri



  • if the file exists or not , when password matches or not the code still runs!
    i guess it is because there is no stop after file generating it is following code and

    IF "<CONFIGPASSWORD>" EqualTo "MySecretPassword"
    JUMP #START
    ENDIF
    

    this also not works because i guess <COFIGPASSWORD> is not defined when config is stated



  • @Ruri

    SET VAR "PASS" "MySecretPassword"
    SET VAR "PASSFILE" "MyConfigPassword.txt"
    IF "<PASSFILE>" DoesNotExist
    UTILITY File "<PASSFILE>" Write "Type Password" 
    JUMP #STOP
    ENDIF
    

    It is not creating file


  • Admin

    The file will be located in the same folder as the OB executable. If it's not creating one, maybe OB is lacking permissions to create it.



  • @Ruri My edited and working one

    SET VAR "PASS" "MySecretPassword"
    SET VAR "PASSFILE" "MyConfigPassword.txt"
    
    UTILITY File "<PASSFILE>" Read -> VAR "READ" 
    
    IF "<READ>" EqualTo "<PASS>"
    JUMP #START
    ENDIF
    IF "<READ>" DoesNotExist
    
    UTILITY File "<PASSFILE>" Write "ENTERPASS" 
    
    SET CAP "CHECK OB FOLDER" "ENTER PASSWORD"
    JUMP #STOP
    ELSE
    SET CAP "PASSWORD INCORRECT" "PASSWORD INCORRECT"
    JUMP #STOP
    ENDIF
    #START 
    
    FUNCTION Constant "Start of the config" -> VAR "start" 
    
    #STOP
    

Log in to reply