# Finding hard coded passwords

**URL:** <https://community.sonarsource.com/t/finding-hard-coded-passwords/4090>\
**Category:** SonarQube Server / Community Build\
**Tags:** security, rules\
**Created:** [November 8, 2018, 8:48am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090 "2018-11-08T08:48:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boris](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@Boris](https://community.sonarsource.com/u/Boris)\
**Post date:** [November 8, 2018, 8:48am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/1 "2018-11-08T08:48:05Z")

</div>

Hello,  
I am trying to understand if it is possible to find hard coded passwords in code with SQ? Has anybody used SQ for this purpose? If so,can you please tell how it works? Just looking for some variables like “PWD” or “PASSWORD” or using mor sophisticated methodologies?

thanks in advance.

---

<div class="post-metadata">

**Author:** ![agabrys](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/agabrys/32/2744_2.png) [@agabrys](https://community.sonarsource.com/u/agabrys)\
**Post date:** [November 8, 2018, 9:52am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/2 "2018-11-08T09:52:31Z")

</div>

SonarSource provides a rule for such purposes: [Credentials should not be hard-coded](https://rules.sonarsource.com/java/RSPEC-2068).

---

<div class="post-metadata">

**Author:** ![Nicolas\_Peru](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicolas_peru/32/22_2.png) [@Nicolas\_Peru](https://community.sonarsource.com/u/Nicolas_Peru)\
**Post date:** [November 8, 2018, 3:28pm UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/3 "2018-11-08T15:28:51Z")

</div>

and you can check the implementation to see it is quite naive/brute force approach in java : [https://github.com/SonarSource/sonar-java/blob/dfdf526f4b3446e181e6a869be9410400ce0499e/java-checks/src/main/java/org/sonar/java/checks/HardCodedCredentialsCheck.java](https://github.com/SonarSource/sonar-java/blob/dfdf526f4b3446e181e6a869be9410400ce0499e/java-checks/src/main/java/org/sonar/java/checks/HardCodedCredentialsCheck.java)

---

<div class="post-metadata">

**Author:** ![Boris](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@Boris](https://community.sonarsource.com/u/Boris)\
**Post date:** [November 8, 2018, 4:15pm UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/4 "2018-11-08T16:15:15Z")

</div>

Yeap…I understand that it is the best we can do with SC,right? No sophisticated methodology…

Thanks.

![](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/f/f003192a1f3cbff81737c51a6c1ed5f5dd97394e.jpeg)

---

<div class="post-metadata">

**Author:** ![Nicolas\_Peru](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicolas_peru/32/22_2.png) [@Nicolas\_Peru](https://community.sonarsource.com/u/Nicolas_Peru)\
**Post date:** [November 9, 2018, 8:08am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/5 "2018-11-09T08:08:55Z")

</div>

I am not sure what you are looking for but to find hardcoded password there can only be so much techniques to highlight pieces of code where something is hardcoded.

Could you eventually clarify what you have in mind ?

---

<div class="post-metadata">

**Author:** ![Boris](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@Boris](https://community.sonarsource.com/u/Boris)\
**Post date:** [November 12, 2018, 10:21am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/6 "2018-11-12T10:21:15Z")

</div>

The thing is i dont have something well defined in mind. What i know is ; i have to find hardcoded passwords with maximum accuracy. This is the requirement.

Only the solution i can think of is what you suggested: Search for piece of code. But it is obvious that still some passwords may be missed and there may be false positives.

So i am wondering, may be there is a better way or technique that i cant just think of.

Just to give an example; sometime ago i was trying to find and classify code files according to programming languages those codes were programmed with. Only way i could think of was looking at the extension of the file name. But after some research on internet i found an algorithm. With this algorith it was possible to train the code with sample code pieces and then code was able to find programming languages used with %95 accuracy.

Hope this explains.

![](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/f/f003192a1f3cbff81737c51a6c1ed5f5dd97394e.jpeg)

---

<div class="post-metadata">

**Author:** ![apanno](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/apanno/32/16773_2.png) [@apanno](https://community.sonarsource.com/u/apanno)\
**Post date:** [March 9, 2021, 2:21pm UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/7 "2021-03-09T14:21:43Z")

</div>

Hi,  
Is this rule applies only to java or to many of the programming languages supported by the tool?

Thanks

---

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [March 10, 2021, 9:20am UTC](https://community.sonarsource.com/t/finding-hard-coded-passwords/4090/8 "2021-03-10T09:20:25Z")

</div>

Hello,

The rule is available for 19 languages:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/6/d6da359a0eb4c80ce6a24823b41d34c2cda59220.png)

Alex
