Character Analysis
Professor Lockhart is the second Defense Against the Dark Arts teacher they've had in as many years. In addition to embarking on his new teaching career, Professor Lockhart is also busy marketing himself. He's got a line of books (Break with a Banshee, Gadding with Ghouls, Holidays with Hags, etc.) that give full details about how awesome, heroic, and beautiful Professor Lockhart is. In fact, Harry, Ron, and Hermione first meet Lockhart at a book signing of his new autobiography, Magical Me, where he is surrounded "by large pictures of his own face, all winking and flashing dazzlingly white teeth at the crowd" (4.156). As you may guess from this introduction, Professor Lockhart's primary characteristic is that he is extremely, extremely vain.
Like many vain people, Professor Lockhart is also quite insecure. He can't stand to share the limelight with anyone else. He clearly feels threatened by Harry Potter's fame and takes care to run him down when he can: "Let me just say that handing out signed pictures at this stage of your career isn't sensible – looks a tad bigheaded, Harry, to be frank" (6.105). Of course, if anyone is bigheaded, it's Professor Lockhart. He's just jealous of Harry. He even goes so far as to force Harry to help him sign autographs for detention (which is, incidentally, when Harry first hears the basilisk in the Hogwarts walls).
Professor Lockhart's vanity and insecurity would be easier to stand if he was capable of doing anything at all. Of course, he isn't: in his first class with the second years, he releases a bunch of Cornish pixies to wreck the classroom and then can't figure out how to stop them. He drops his wand while trying to teach Harry a Disarming Charm during the first and last meeting of his Dueling Club. Most pathetic of all, when Harry breaks his arm during his Quidditch match against Slytherin, Professor Lockhart manages to remove all the bones in his arm rather than fix them.
So Professor Lockhart is quite pathetic. We only discover how sinister he can be at the end of the novel, when he tries to cast a Memory Charm on Harry and Ron. The two boys have found out that Professor Lockhart's books are all a pack of lies. He's been taking credit for things other people have done by using memory modification spells (his one talent). The only thing that saves Harry and Ron from the same thing is Ron's broken wand, which backfires on Professor Lockhart and gives him complete, incurable amnesia. Throughout the book, we've rolled our eyes at Professor Lockhart's stupid antics. In this final scene in the tunnel on the way to the Chamber of Secrets, though, we see how powerful self-centeredness can really be. Professor Lockhart is willing to leave Ginny to die and to modify Harry and Ron's memories just so that he can maintain his reputation. He may be a weak coward, but that's why he's surprisingly dangerous.
J.K. Rowling has claimed that Professor Lockhart is the only character in the Harry Potter novels who is based directly on a real person:
The only character who is deliberately based on a real person is Gilderoy Lockhart. [Laughter]. Maybe he is not the one that you would think of, but I have to say that the living model was worse. [Laughter]. He was a shocker! The lies that he told about adventures that he'd had, things he'd done and impressive acts that he had committed…He was a shocking man. I can say this quite freely because he will never in a million years dream that he is Gilderoy Lockhart. I am always frightened that he is going to turn up one day. He is just one of those people from your past whom you feel you have never quite shaken off. I will look up one day at a signing and he will say, "Hello, Jo". [Laughter]. Other people have contributed the odd characteristic, such as a nose, to a character, but the only character who I sat down and thought that I would base on someone is Gilderoy Lockhart. It made up for having to endure him for two solid years. (source)