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

    +143

    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
    class Security{
        
        private $workFactor, $salt;
        
        public function __construct(){
            $this->setWorkFactor();
            $salt = $this->getSaltBytes();
            $this->setSalt($salt);
        }
        
        public function hash($password, $workFactor = 6){
            $options = [
                'cost' => (int)$workFactor,
                'salt' => $this->getSalt()
            ];
            $hash = password_hash($password, PASSWORD_BCRYPT, $options);
            return $hash;
        }
    
        public function checkHash($password, $passwordHash, $options = []){
            if( isset($options['salt'])){
                $this->setSalt($options['salt']);
            }
            $workFactor = isset($options['workFactor']) ? 
                    $options['workFactor'] : $this->getWorkFactor();
            return $passwordHash === $this->hash($password, $workFactor);
        }
        
        public function isLegacyHash($passwordHash){
            return strlen($passwordHash) === 60;
        }
        
        public function getSalt(){
            return $this->salt;
        }
        
        public function setSalt($salt){
            $this->salt = $salt;
        }
        
        public function getSaltBytes($lenght = 24){
            return $this->getRandomBytes($lenght);
        }
    
        public function getRandomBytes($lenght = 24){
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $lenght; $i++){
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }
        
        public function setWorkFactor($workFactor = 6){
            $this->workFactor = (int)$workFactor;
        }
        
        public function getWorkFactor(){
            return $this->workFactor;
        }
        
    }

    Besmer, 28 Мая 2015

    Комментарии (28)
  2. SQL / Говнокод #18252

    −161

    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
    CREATE TABLE [dbo].[Images](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[category] [int] NOT NULL,
    	[tag] [nvarchar](16) NOT NULL,
    	[description] [nvarchar](128) NOT NULL,
    	[comment] [nvarchar](1024) NULL,
    	[code01] [nvarchar](max) NULL,
    	[code02] [nvarchar](max) NULL,
    	[code03] [nvarchar](max) NULL,
    	[code04] [nvarchar](max) NULL,
    	[code05] [nvarchar](max) NULL,
    	[code06] [nvarchar](max) NULL,
    	[code07] [nvarchar](max) NULL,
    	[code08] [nvarchar](max) NULL,
    	[code09] [nvarchar](max) NULL,
    	[code10] [nvarchar](max) NULL,
    	[code]  AS (rtrim(((((((((((((((((((((((((((((rtrim(replace(replace(coalesce([code01],''),char((13)),' '),char((10)),' '))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code02],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code03],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code04],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code05],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code06],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code07],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code08],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code09],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10)))+rtrim(replace(replace(coalesce([code10],''),char((13)),' '),char((10)),' ')))+char((13)))+char((10))))
    )

    10 нормальная форма (_*_)

    drup, 28 Мая 2015

    Комментарии (53)
  3. Куча / Говнокод #18251

    +146

    1. 1
    <span class="enrty-comments-count">(0)</span>

    Enligsh lagnauge rluze.

    inkanus-gray, 28 Мая 2015

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

    +142

    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
    public class DaoFactory {
    
        private Map<Class<?>, Class<?>> daos = null;
        
        public DaoFactory()  {
             init();
        }
        
        private void init() {
            this.daos = new HashMap<>();
            this.daos.put(AllSettings.class, AllSettingsDao.class);
            this.daos.put(ClientProfile.class, ClientProfileDao.class);
        }
    
        public EntityDao<?> getDao(Class<?> entityClass) {
        	EntityDao<?> dao = null;
    	try {
    	    if(daos.containsKey(entityClass)) {
    	    	dao = (EntityDao<?>)daos.get(entityClass).newInstance();
    	    } 
    	} catch (Exception e) {
    	    e.printStackTrace();
    	}
    	return dao;
        }
    }

    Фабрика Dao для сущностей

    carapuz, 28 Мая 2015

    Комментарии (0)
  5. PHP / Говнокод #18249

    +144

    1. 1
    if ((int)$qty && ((int)$qty > 0)) {

    OpenCart

    OverOverMind, 28 Мая 2015

    Комментарии (0)
  6. PHP / Говнокод #18248

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $flag = "yes";
    /* ... */
    if($flag) {
        $flag = $flag;
    }

    dgkj, 28 Мая 2015

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

    +142

    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
    // Check if the subnet begins with $startip and ends before $endip
    if (($targetsub_min == $startip) && ip_less_than($targetsub_max, $endip)) {
    	break;
    }
    
    // Check if the subnet ends at $endip and starts after $startip
    if (ip_greater_than($targetsub_min, $startip) && ($targetsub_max == $endip)) {
    	break;
    }
    
    // Check if the subnet is between $startip and $endip
    if (ip_greater_than($targetsub_min, $startip) && ip_less_than($targetsub_max, $endip)) {
    	break;
    }

    Коль уж старые посты потерлись, принесу это говно снова. Я тогда самое главное забыл. Теперь эти пидорасы не оправдаются ущербностью PHP.

    https://github.com/pfsense/pfsense/blob/master/etc/inc/util.inc#L542-L555

    superhacker777, 27 Мая 2015

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

    +143

    1. 1
    http://govnokod.ru/comments/18245/rss ru [email protected] (govnokod.ru support) Mzz.Framework v.100500-release Wed, 27 May 2015 21:20:29 +0400 Fatal error: Call to a member function getCreated() on a non-object in /home/striker/applications/govnokod/tmp/templates_c/1563503196.file.export_quote_rss.tpl.php-ru.php on line 21

    http://govnokod.ru/, в чём дело:

    Dev_18, 27 Мая 2015

    Комментарии (10)
  9. JavaScript / Говнокод #18245

    +142

    1. 1
    Код не мой, но очень неоптимизированный. И так ещё десяток таких блоков. С сайта: http://ninjahonor.com/.

    $(document).ready(function(){
    $(".coffin-box1 a.name1").click(function(){
    $(".vid1").addClass('active')
    $(".vid2 , .vid3 , .vid4 , .vid5 , .vid6 , .vid7 , .vid8 , .vid9 , .vid10 , .vid11 , .vid12 , .vid13 , .vid14 , .vid15 , .vid16 , .vid17 , .vid18 , .vid19 , .vid20 , .vid21 , .vid22 , .vid23 , .vid24 , .vid25 , .vid0 ").removeClass('active')
    });
    });

    $(document).ready(function(){
    $(".coffin-box1 a.name2").click(function(){
    $(".vid2").addClass('active')
    $(".vid1 , .vid3 , .vid4 , .vid5 , .vid6 , .vid7 , .vid8 , .vid9 , .vid10 , .vid11 , .vid12 , .vid13 , .vid14 , .vid15 , .vid16 , .vid17 , .vid18 , .vid19 , .vid20 , .vid21 , .vid22 , .vid23 , .vid24 , .vid25 , .vid0 ").removeClass('active')
    });
    });
    $(document).ready(function(){
    $(".coffin-box2 a.name1").click(function(){
    $(".vid6").addClass('active')
    $(".vid2 , .vid3 , .vid4 , .vid5 , .vid1 , .vid7 , .vid8 , .vid9 , .vid10 , .vid11 , .vid12 , .vid13 , .vid14 , .vid15 , .vid16 , .vid17 , .vid18 , .vid19 , .vid20 , .vid21 , .vid22 , .vid23 , .vid24 , .vid25 , .vid0 ").removeClass('active')
    });
    });

    Dev_18, 27 Мая 2015

    Комментарии (54)
  10. Python / Говнокод #18244

    −120

    1. 1
    sqlalchemy.orm.relationship(argument, secondary=None, primaryjoin=None, secondaryjoin=None, foreign_keys=None, uselist=None, order_by=False, backref=None, back_populates=None, post_update=False, cascade=False, extension=None, viewonly=False, lazy=True, collection_class=None, passive_deletes=False, passive_updates=True, remote_side=None, enable_typechecks=True, join_depth=None, comparator_factory=None, single_parent=False, innerjoin=False, distinct_target_key=None, doc=None, active_history=False, cascade_backrefs=True, load_on_pending=False, strategy_class=None, _local_remote_pairs=None, query_class=None, info=None)

    Охуенный АПИ: прочитал и сразу запомнил.

    wvxvw, 27 Мая 2015

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