How can I hash a password in Java?

前端 未结 13 2228
暖寄归人
暖寄归人 2020-11-22 05:00

I need to hash passwords for storage in a database. How can I do this in Java?

I was hoping to take the plain text password, add a random salt, then store the salt a

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 05:27

    i leaned that from a video on udemy and edited to be stronger random password

    }
    
    private String pass() {
            String passswet="1234567890zxcvbbnmasdfghjklop[iuytrtewq@#$%^&*" ;
    
            char icon1;
            char[] t=new char[20];
    
             int rand1=(int)(Math.random()*6)+38;//to make a random within the range of special characters
    
                icon1=passswet.charAt(rand1);//will produce char with a special character
    
            int i=0;
            while( i <11) {
    
                 int rand=(int)(Math.random()*passswet.length());
                 //notice (int) as the original value of Math>random() is double
    
                 t[i] =passswet.charAt(rand);
    
                 i++;
                    t[10]=icon1;
    //to replace the specified item with icon1
             }
            return new String(t);
    }
    
    
    
    
    
    
    }
    

提交回复
热议问题