Skip to content
lsl.devlsl.devLSL Dev

Authenticated Chat

Here's a method of authenticating chat with shared secret.
//By: Gigs Taggart
//Modified by Strife Onizuka
//Released under BSD license

string  gSetupNotecardName = "setup";

string  gPassword;
integer gSeed;

key     gSetupQueryId;
integer gSetupNotecardLine;

//to sign a message we hash message+gSecret+llGetKey()
string sign_message(string message)
{
    string hash = llMD5String(message + gPassword + (string)llGetKey(), gSeed);
    return message + hash;
}

//to verify a message we do all the same stuff except we get the sender's key
integer verify_message(string raw, key sender)
{
    string hash = llMD5String(llDeleteSubString(message, -32, -1) + gPassword + (string)sender, gSeed);
    return llGetSubString(message, -32, -1) == hash;
}

readSettingsNotecard()
{
   gSetupNotecardLine = 0;
   gSetupQueryId = llGetNotecardLine(gSetupNotecardName, gSetupNotecardLine); 
}


default
{
    state_entry()
    {
         readSettingsNotecard();
    }
    dataserver(key queryId, string data)
    {
        if(queryId == gSetupQueryId) 
        {
            if(data != EOF)
            {
                integer split = llSubStringIndex(data, "=");
                if(~split)
                {
                    string setting = llDeleteSubString(data, split, -1);
                    string value   = llDeleteSubString(data, 0,  split);
                    if (setting == "password")
                    {
                        gPassword = value;
                    }
                    else if(setting == "seed")
                    {
                        gSeed = (integer)value;
                    }
                }
                gSetupQueryId = llGetNotecardLine(gSetupNotecardName, ++gSetupNotecardLine); 
            }
            else
            {
                state running;   
            }
        }
    }           
    changed(integer change)
    {
        llResetScript();
    }
}

state running
{

    changed(integer change)
    {
        llResetScript();
    }
}

Notecard

Name: "setup"
password=secret
seed=0xdeadbeef
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from Authenticated Chat, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.