Jump to content

Convert a number to sha1 in if statement


Nexy

Recommended Posts

Why Hello There! :) Just wondering on how to do this:

 

How do I check if a number inside an if statement == a certain number and if it does: make it sha1(number). I have these if statements around several pages, so I was wondering if I could do it this way instead of writing sha1(number) everywhere.

 

Example:

 

if($_SESSION['id'] == 495) I want some code to catch that 495 and turn it into:

if($_SESSION['id'] == sha1(495))

 

Any help would be appreciated! Thank You!!  :)

You will need your "certain number" to be a variable

 

<?php

$number = 495;

if($_session['id'] == $number) {
  
  // Make the sha1 hash
  $hash = sha1($number);

  // Or run the other if statement, I'm not sure what you wanna do ?
  if($_session['id'] == sha1($number)) {
    // Do something else
  }

}
?>

I'm using this for moderation levels, since I use cookies and sessions, I made random numbers to represent a certain level. Since I also use cookies, I didn't want anyone changing the value so easily. Basically, I have 4 diff random numbers and I sha1 them at the creation once the user logs in.

 

On different pages I have something like: if($_SESSION['id'] == 658 || $_COOKIE['id'] == 658), depending if they are using cookies or not.

 

I'll try those 2 ways. Thank You!  :)

Well, with your way, could a hacker manipulate the variables? As in change them?

 

If I had:

 

$member = sha1(392);

$admin = sha1(333);

 

if($_SESSION['id'] == $member)

 

Could a hacker be able to change the variables? If so, any way to protect from that?

 

Thank You!  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.