openmsg.io
Generating Pass Codes
See first: Setup: Guide
See first: Handshake: Guide


For a User on one Node to be able to send a message to a different User, the User will need to give the other User their Openmsg address, and also a one-time, 6 digit pass_code. This pass_code has an expire of 1 hour and can only be used once. Below is some example code for a Node to be able to generate a truly random, non-predictable 6 digit code.
Code
PHP
.php
<?php
    
    // This page should be in the User's login protected area
    $self_openmsg_address = ""; // Enter the Openmsg address that requested the code.
    function generateRandomString($length = 6) {
        $characters = '0123456789';
        $charactersLength = strlen($characters);
        $randomString = '';
    
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[random_int(0, $charactersLength - 1)];
        }
    
        return $randomString;
    }

    $new_pass_code = generateRandomString(6);
    
    $stmt = $db->prepare("INSERT INTO openmsg_passCodes  (self_openmsg_address, pass_code) VALUES (?, ?)");
    $stmt->bind_param("ss", $self_openmsg_address, $new_pass_code);
    //$stmt->execute();
    $stmt->close();
    
    //echo "Hi User, here is your Pass Code: ".$new_pass_code.". It expires in 1 hour.";

?>
!Important
The Receiving Node MUST receive a valid pass_code to authorize the sender. This is core to Openmsg.
To finish
To do
You should remove any pass_codes from the table that are over 60 minutes old.
Recap
  • The User requests a pass_code from their Receiving Node (the provider of their Openmsg account)
  • The Node then generates and stores the Pass Code along with the current timestamp (Pass Codes should be expired after 1 hour), and the requesting User's Openmsg address, and displays the code to the User for them to use
Next