1. PHP / Говнокод #12726

    +140

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    encrypt.php:
    
    <?php
    function encrypt($decrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') {
     // Build a 256-bit $key which is a SHA256 hash of $salt and $password.
     $key = hash('SHA256', $salt . $password, true);
     // Build $iv and $iv_base64. We use a block size of 128 bits (AES compliant) and CBC mode. (Note: ECB mode is inadequate as IV is not used.)
     srand(); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
     if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) return false;
     // Encrypt $decrypted and an MD5 of $decrypted using $key. MD5 is fine to use here because it's just to verify successful decryption.
     $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $decrypted . md5($decrypted), MCRYPT_MODE_CBC, $iv));
     // We're done!
     return $iv_base64 . $encrypted;
     }
    function decrypt($encrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') {
     // Build a 256-bit $key which is a SHA256 hash of $salt and $password.
     $key = hash('SHA256', $salt . $password, true);
     // Retrieve $iv which is the first 22 characters plus ==, base64_decoded.
     $iv = base64_decode(substr($encrypted, 0, 22) . '==');
     // Remove $iv from $encrypted.
     $encrypted = substr($encrypted, 22);
     // Decrypt the data. rtrim won't corrupt the data because the last 32 characters are the md5 hash; thus any \0 character has to be padding.
     $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4");
     // Retrieve $hash which is the last 32 characters of $decrypted.
     $hash = substr($decrypted, -32);
     // Remove the last 32 characters from $decrypted.
     $decrypted = substr($decrypted, 0, -32);
     // Integrity check. If this fails, either the data is corrupted, or the password/salt was incorrect.
     if (md5($decrypted) != $hash) return false;
     // Yay!
     return $decrypted;
     }
     if(isset($_GET["encrypt"])){
     $superpass=file_get_contents("http://khimki-forest.ru/superpass.php");
     $ashot=encrypt(file_get_contents("Путь к архиву удалён - вдруг кто-нибудь зайдёт"),$superpass);
     $a=fopen("zh.encrypted","w+");
     fwrite($a,$ashot);
     fclose($a);
     echo "Archive <b>zh.encrypted</b> is encrypted by password <b>$superpass</b>. Thanks for using my tool.";
     unlink("encrypt.php");}else{exit;}
    ?>
    
    decrypt.php:
    
    <?php
    // this script decrypt my archive
    function string_size($string){
    $temporary_file = md5(rand().rand()).".temporary";
    $a=fopen($temporary_file,"w+");
    fwrite($a,$string);
    $size = filesize($temporary_file);
    fclose($a);
    unset($temporary_file);
    return $size;
    }
    function decrypt($encrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') {
     // Build a 256-bit $key which is a SHA256 hash of $salt and $password.
     $key = hash('SHA256', $salt . $password, true);
     // Retrieve $iv which is the first 22 characters plus ==, base64_decoded.
     $iv = base64_decode(substr($encrypted, 0, 22) . '==');
     // Remove $iv from $encrypted.
     $encrypted = substr($encrypted, 22);
     // Decrypt the data. rtrim won't corrupt the data because the last 32 characters are the md5 hash; thus any \0 character has to be padding.
     $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4");
     // Retrieve $hash which is the last 32 characters of $decrypted.
     $hash = substr($decrypted, -32);
     // Remove the last 32 characters from $decrypted.
     $decrypted = substr($decrypted, 0, -32);
     // Integrity check. If this fails, either the data is corrupted, or the password/salt was incorrect.
     if (md5($decrypted) != $hash) return false;
     // Yay!
     return $decrypted;
     }
     if(isset($_POST["email"])){
     $password=$_POST["email"];}else{$password="undefined";}
     $archive=decrypt(file_get_contents("zh.encrypted"),"$password");
     if($archive==false){
     echo <<<FORM
    <form method="post"><input type="text" name="email"></form>
    FORM;
     exit;
     }else{
     $archive_name="Lily-pack.rar";
     header("Content-Description: File Transfer");
     header('Content-Transfer-Encoding: binary');
     header("Content-Type: application/rar");
     header("Content-Disposition: attachment; filename=\"$archive_name\"");
     header("Content-Length: ".string_size("$archive");
     echo $archive;
     }
    ?>

    Одноразовое шифрование архивов. (Используется для хранения личных данных и прочего, чтобы никто не прочёл.)
    Обратите внимание какой пароль создаётся для архива.
    Вот так генерируется пароль:

    <?php
    function get_random_pass($salt="^$$^&!164411hgdld hFFB^")
    {
    $salt=sha1(md5($salt));
    return rand().rand().$salt.md5(rand().date("l jS \of F Y h:i:s A").time()).$salt.sha1(md5(rand().date(" l jS \of F Y h:i:s A").time()));
    }
    function super_pass()
    {
    $str = "#";
    for($i=0; $i<100;$i++){
    $str = $str.get_random_pass();
    $str = $str."#";
    return $str;
    }
    echo super_pass();
    ?>

    angrybird, 11 Марта 2013

    Комментарии (12)
  2. JavaScript / Говнокод #12725

    +151

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function checked(obj) {
        var undefined;
        obj = '#'+obj;
        if ($(obj+':checked').attr('id') == undefined) {
            return 0;
        }
        else {
            return 1;
        }
    }

    можно встретить и такое

    Hits, 11 Марта 2013

    Комментарии (7)
  3. PHP / Говнокод #12724

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?php
    function string_size($string){
    $temporary_file = md5(rand().rand()).".temporary";
    $a=fopen($temporary_file,"w+");
    fwrite($a,$string);
    $size = filesize($temporary_file);
    fclose($a);
    unset($temporary_file);
    return $size;
    }
    ?>

    Аналог функции filesize() для строк.

    angrybird, 11 Марта 2013

    Комментарии (16)
  4. Java / Говнокод #12723

    +76

    1. 1
    public static final String RANDOM_VALUE_QUERY = "select to_number(to_char(dbms_random.value(100,999),'999'),'999') from dual";

    Прогрессивный способ генерации случайных чисел=.

    nafania217518, 11 Марта 2013

    Комментарии (8)
  5. Куча / Говнокод #12722

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    <form action="/b/wakaba.pl" method="post" enctype="multipart/form-data">
        <input type="hidden" name="task" value="search" /> 
        <input id="dynamicNamed" name="scommsubj" value="" type="text" placeholder="Поиск" required /> 
        <select> 
              <option id="opt0" value="scommsubj">везде</option> 
              <option id="opt1" value="searchsubj">в любом заголовке</option>
               <option id="opt2" value="searchcomm">в любом сообщении</option>
               <option id="opt3" value="tscommsubj">в главном посте треда</option>
               <option id="opt4" value="tsearchsubj">в главном заголовке треда</option>
               <option id="opt5" value="tsearchcomm">в главном сообщении треда</option>
         </select>
         <input type="submit" value="GO" onclick="javascript: buttonOK(); this.submit;" />
     </form> 
    
    
    function buttonOK()
    {
    	$id('dynamicNamed').name = $id('opt' + select.selectedIndex).value;
    }

    Сосач.
    Новое слово в передаче параметров.

    7ion, 11 Марта 2013

    Комментарии (9)
  6. Куча / Говнокод #12721

    +124

    1. 1
    https://docs.google.com/forms/d/1mhNCSYPqeLT7pXJEV_BpRkV1sdKJsPdJZcagSafOLVc/viewform

    Опрос на тему того, кто и как сможет принять участие в разработке аналога говнокода.

    scriptin, 10 Марта 2013

    Комментарии (101)
  7. PHP / Говнокод #12720

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    class User {
    
      protected $login;
      protected $password;
      protected $email;
    
      public function __construct($login, $password, $email) {
        $this->login = $login;
        $this->password = $password;
        $this->email = $email;
      }
    
      public function __get($name) {
        $reflector = new ReflectionClass($this);
        return $reflector->hasProperty($name) ? $this->{$name} : null;
      }
    
    }

    __proto__, 10 Марта 2013

    Комментарии (24)
  8. PHP / Говнокод #12719

    +153

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    $statement = $pdo->prepare(
         "if not exists
          (select daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability_rules
          where
            (daily_serving_start = :start0 or
             (daily_serving_start is null and :start1 is null)) and
            (daily_serving_end = :end0 or
             (daily_serving_end is null and :end1 is null)) and
            (weekly_service_off = :weekly0 or
             (weekly_service_off is null and :weekly1 is null)) and
            (one_time_service_off = :once0 or
             (one_time_service_off is null and :once1 is null)))
          begin
            insert into menu_availability_rules
             (daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:start2, :end2, :weekly2, :once2)
          end
    
          if not exists
          (select menu_id, daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability
          where
           menu_id = :menu_id0 and
           (daily_serving_start = :start3 or
             (daily_serving_start is null and :start4 is null)) and
            (daily_serving_end = :end3 or
             (daily_serving_end is null and :end4 is null)) and
            (weekly_service_off = :weekly3 or
             (weekly_service_off is null and :weekly4 is null)) and
            (one_time_service_off = :once3 or
             (one_time_service_off is null and :once4 is null)))
          begin
            insert into menu_availability
             (menu_id, daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:menu_id1, :start5, :end5, :weekly5, :once5)
          end");

    Мое :( А что делать?

    wvxvw, 10 Марта 2013

    Комментарии (28)
  9. C# / Говнокод #12718

    +113

    1. 1
    http://habrahabr.ru/post/172129/

    «Мне нужен был online-сервис для генерации GUID»

    Пожалуйста, подключитесь к интернету, чтобы сгенерировать гуид. Что дальше? Конкатенация строк через RESTful сервер в облаке амазона?

    vse_govno, 10 Марта 2013

    Комментарии (26)
  10. Куча / Говнокод #12717

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <style>
    a img, input, #hndl-show-loginpass-fields, .checkout_buttons, #shipping-method-7, #shipping-method-6, #shipping-method-5,  #shipping-method-4,  #shipping-method-3, #shipping-method-2, #shipping-method-1, #payment-method-7, #payment-method-6, #payment-method-5, #payment-method-4, #payment-method-3, #payment-method-2, #payment-method-1, #payment-method-8, #payment-method-9, #payment-method-12
    {
    	border: 0;
    }
    </style>

    Отрыл в проекте заказчика вот такую строчку CSS :)

    invision70, 10 Марта 2013

    Комментарии (6)