Since Gimli was very proud of the dwarves hospitality, how come he didn't know the password to enter the mines?
In the books, at least, the west gate of Moria had not been used for 1,037 to 4,763 years, making it unlikely that the password had been handed down to Gimli. The movies have a much less certain history and chronology, so I don't know how long it had been in the movies since the west gate had been in use. In the books the family of the craftsman who made the gates was said to be extinct and the password forgotten.
Gimil was a member of the Longbeards, or Durin's Folk, the most senior of the seven races of the Dwarves, and the race who had lived in Moria long ago.
Gimil was a member of the royal family of the Longbeards. According to the royal family tree, and the birth and date deaths of its members, in the year that the Fellowship of the Ring entered Moria, Third Age 3019, Gimil was officially sixth in line for the throne.
The King was Dain II Ironfoot (2267-3019) and his heirs were:
- Son who became King Thorin III Stonehelm (born 2866).
- Cousin Balin son of Fundin (2763-2994)
- Cousin Dwailin son of Fundin (2772-3112)
- Cousin Oin son of Groin (2774-2994)
- Cousin Gloin son of Groin (2783-Fourth Age 15)
- Gimili son of Gloin (2879-Fourth Age 100).
By TA 3019 it was suspected but not yet confirmed that Balin and Oin were dead. Dwallin's death year of Third Age 3112 was after the start of the Fourth Age and would make him live to be 340. If 3112 was a mistake for 3012 it would make Dwailin live for a more normal Dwarf life span of 240 years.
Thus it may be guessed that that in 3019 Gimil was actually third or fourth in line for the double Kingship, Kingship of the Longbeard race and of the Kingdom Under the Mountain.
See The Return of the King, Appendix A, Annals of the Kings and Rulers, III, Durin's Folk.
Moria was founded by King Durin I The Deathless back in the Elder Days. In the Second Age, in the reign of Durin III, the Elves of Eregon or Hollin under Celebrimbor were friendly with the Dwarves of Moria, and the west gates were made.
The Return of the King, Appendix B, the Tale of the Years, gives some important dates.
1697 Eregon laid waste. Death of Celembrimbor. The gates of Moria are shut. Elrond retreats with remnant of the Noldor and founds the refuge of Imladris
1700 Sauron is driven out of Eriador. The Westlands have peace for a long while.
It is possible that Moria began letting visitors use the west gate again after SA 1700, but that is not stated.
3441 Sauron is overthrown by Elendil and Gil-glad, who perish. Isildur takes the One Ring. Sauron passes away and the Ringwraiths go into the shadows. The Second Age ends.
It is possible that Moria began letting visitors use the west gate again after SA 3441, but that is not stated.
1050 Hyarmendacil conquers the Harad. Gondor Reaches the height of its power. At this time a shadow falls on Greenwood, and Men begin to call it Mirkwood. The Periannath are first mentioned in records, with the coming of the Harfoots to Eriador.
c. 1100 The Wise (The Istari and the chief Eldar) discover that an evil power has made a stronghold at Dol Guldur. It is thought to be one of the Nazgul.
c. 1300 Evil things begin to multiply again. Orcs increase in the Misty Mountains and begin to attack the Dwarves. The Nazgul reappear. The chief of these comes north to Angmar. The Periannath migrate westward; many settle at Bree.
If the west gate of Moria had been reopened for traffic after the overthrow of Sauron, the Dwarves might have shut it again at the year 1050, or at c. 1100, or at c. 1300, as the outside world became more dangerous. But there is no record.
1980 The Witch-King comes to Mordor and there gathers the Nazgul. A Balrog appears in Moria, and slays Durin VI.
1981 Nain I slain. The Dwarves flee from Moria. Many of the Silvan Elves of Lorien flee south. Amroth and Nimorodel are lost.
1999 Thrain I comes to Erebor and founds a Dwarf-kingdom 'under the mountain'.
2210 Thorin I leaves Erebor, and goes north to the Grey Mountains, where most of the remnants of Durin's Folk are now gathering.
2589 Dain I slain by a dragon.
2590 Thror returns to Erebor. Gror his brother goes to the Iron Hills.
2770 Smaug the Dragon descends on Erebor. Thror escapes with Thrain II and Thorin II.
TA 2941 The events of The Hobbit.
TA 3018 to 3019. The events of The Lord of the Rings, including the Fellowship of the Ring travelling through Moria during January 13-15, 3019.
So Moria was abandoned by Dwarves and occupied by evil beings for 1,037 to 1,038 years before the Fellowship of the Ring entered Moria. As far as is known nobody used the west gate to enter Moria after Third Age 1981, 1,037 to 1,038 years earlier, and there were no Dwarves in Moria to have anything to do with such improbable travelers in all those years.
And how often did the Dwarves of Moria let travelers in through the west gate in the years before they were driven out of Moria? Third Age 1981 was equivalent to about Second Age 5422, which would be 3,725 years after it was recorded that the gates of Moria were shut in Second Age 1697. And there is no record in The Lord of the Rings whether the the west gate of Moria was ever used after Second Age 1697.
The eastern gates of Moria must have been opened and used for trade many times in the 3,725 years between SA 1697 and TA 1981, whenever the outside world seemed peaceful enough, but after Eregon was devastated there would have been few people interested in using the west gate of Moria, except possibly to avoid taking the Redhorn Pass, and it is not known if the Dwarves let people use the west gate during any of those 3,725 years.
Thus by TA 3019 the west gate had not been used by visitors for between 1,037 and 4,763 years. Which is a little long for a secret password to be remembered.
The Fellowship of the Ring, Book II, Chapter 4, "A Journey in the Dark", describes the inscription on the west gate of Moria:
They say only: The Doors of Durin, Lord of Moria. speak, friend, and enter And underneath small and faint is written: I, Narvi, made them. Celebrimbor of Hollin drew these signs.
They deduce that a password must have been spoken to open the gates, and Gimli said:
But what the word was is not remembered. Narvi and his craft and all his kindred have vanished from the earth.
So in the novel Gimli directly states that there is no memory or record of the password for the west gate of Moria.
But I don't remember enough dialog from the movies to know what how long it was supposed to be since the west gate had last been used by visitors to Moria or who might have known the password.
He wasn't from Moria.
Gimli was from the Dwarves who settled Erebor. Here' a Quora post that summarizes it nicely.
There are a couple of reason.
As everyone has stated he wasn’t from Moria. He was from the Dwarves who settled Erebor (Lonely Mountain) after the death of Smaug. He was only at the Council of Elrond to warn Bilblo that Sauron was looking for him.
Balin left Erebor years before against the wishes of it’s ruler Dain to reclaim Khazad-dûm (Moria). They had not been heard from in a long time, but it was quite a distance. (In the Books Gimli is concerned and unsure of what happened to Balin.)
The Western Doors were created by Dwarves and Elves working together as Dwarves of Khazad-dûm had a close relationship with the Elves of Eregion before Sauron destroyed that kingdom to get a hold of the Rings of Power. Before that happened the doors were generally open and there was a great deal of trade. After that they tended to remain closed. As far as knowing the passphrase it likely wasn’t considered something they need to pass along by the Dwarves of Khazad-dûm. The Gates say “Speak Friend and Enter” in Elvish and the password is “friend” in Elvish. It’s only an issue with the Fellowship as they are from a from a later age where no one would have just written the passphrase on the door.
Although this is derived from the books, it applies to the films.