Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 10 posts ] 
Author Message
 Post subject: ASP.NET
PostPosted: Mon Oct 24, 2011 15:05 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69725
Location: Your Mum
Who can convert this Pseudocode into ASP.NET code?

Code:
IF $forum_id is not set THEN
    set $forum_id = 0

Set $hash = the first 10 characters of the MD5 hash of $user_id and $forum_id joined by a hyphen (-) (ie. if $user_id was 16 and $forum_id was 5, take the MD5 hash of "16-5"), using the key 'stupidASP'
Set $link = "http://www.beex.co.uk/" and $user_id / $forum_id / $hash


Here it is in PHP, if that helps:

Code:
if (!$forum_id ) {
    $forum_id = 0;   
}
$hash = hash_hmac("md5", $user_id."-".$forum_id, 'stupidASP');
$hash = substr($hash, 0, 10);
$link = 'http://www.beex.co.uk/'.$user_id.'/'.$forum_id .'/'.$hash;

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 15:12 
User avatar
Paws for thought

Joined: 27th Mar, 2008
Posts: 17161
Location: Just Outside That London, England, Europe
Me.

Not on this phone though, so I'll leave it to others.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 15:19 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49244
What does your 'key' do? Is it a salt?

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 15:36 
User avatar
Hibernating Druid

Joined: 27th Mar, 2008
Posts: 49367
Location: Standing on your mother's Porsche
Does it always have to be about food with you?

_________________
SD&DG Illustrated! Behance Bleep Bloop

'Not without talent but dragged down by bass turgidity'


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 16:01 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69725
Location: Your Mum
Craster wrote:
What does your 'key' do? Is it a salt?

Sorry, yeah. I wrote 'key' because that was the name of the variable (it's an API key, you see).

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 18:05 
User avatar
Excellently Membered

Joined: 30th Mar, 2008
Posts: 1268
Location: Behind you!
Is this C# or VB or or some other random ASP .NET language?

Think C# ASPX is just pretty much the same as PHP:

Code:
if (!forum_id ) {
    forum_id = 0;   
}

Just without $.


Not sure I can remember what the old school ASP stuff was though.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 18:09 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69725
Location: Your Mum
What about the salted MD5 hash?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 18:15 
User avatar
Excellently Membered

Joined: 30th Mar, 2008
Posts: 1268
Location: Behind you!
I'm no expert.... I'm not even sure of the definitions but the ASPX projects I do have you can just create a function and pass in the relevent string just as if you were using C#.... so something link this:

Code:
public string CalculateMD5Hash(string input)
{
    // step 1, calculate MD5 hash from input
    MD5 md5 = System.Security.Cryptography.MD5.Create();
    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    byte[] hash = md5.ComputeHash(inputBytes);

    // step 2, convert byte array to hex string
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hash.Length; i++)
    {
        sb.Append(hash[i].ToString("X2"));
    }
    return sb.ToString();
}
An example call:

string hash = CalculateMD5Hash("abcdefghijklmnopqrstuvwxyz");
…returns a string like this:

C3FCD3D76192E4007DFB496CCA67E13B


http://blogs.msdn.com/b/csharpfaq/archi ... 3f00_.aspx


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 18:18 
User avatar
Excellently Membered

Joined: 30th Mar, 2008
Posts: 1268
Location: Behind you!
I'm also using Visual Studio's so I haven't really had to learn anything. I'm also not a web programmer either, I just try my best when supporting other peoples code. I'm so lucky.


Top
 Profile  
 
 Post subject: Re: ASP.NET
PostPosted: Mon Oct 24, 2011 18:59 
Excellent Member

Joined: 30th Mar, 2008
Posts: 489
this could be made better, with more robust value checking etc. but should do the job:

create the function:

Code:
    public string hash_hmac(string message, string key)
    {

        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        byte[] keyByte = encoding.GetBytes(key);


        System.Security.Cryptography.HMACMD5 hmacmd5 = new System.Security.Cryptography.HMACMD5(keyByte);

        byte[] messageBytes = encoding.GetBytes(message);

        byte[] hashmessage = hmacmd5.ComputeHash(messageBytes);

        string hashmessageString = "";

        for (int i = 0; i < hashmessage.Length; i++)
        {
            hashmessageString += hashmessage[i].ToString("X2"); // hex format
        }
        return (hashmessageString);
    }



and use it with:

Code:
        int forum_id = 5;
        int user_id = 16;

        if (forum_id == null)
            forum_id = 0;

        string hash = hash_hmac(String.Format("{0)-{1}", user_id, forum_id), "stupidASP").Substring(0, 10);
        string link = String.Format("http://www.beex.co.uk/{0)/{1}/{2}", user_id, forum_id, hash);


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Majestic-12 [Bot], TheVision, Vogons and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.