There's a common flaw that I can easily detect in amateur writing, (and of course my own) which essentially boils down to all the characters "sounding the same", dialogue-wise anyway. Trying to overcome this problem, however, I find myself going to opposite end of the spectrum, overcompensating, adding so much accent/slang it gets annoying. ("i fancy me some cider, what ya'll say we pounce on over to the ol' waterin' hole", etc). How do you give each character his/her own unique voice without making it sound forced?
The best way to avoid this problem is to understand your characters as deeply as possible, and remember that it is the character who should speak, and not you, the author. The things characters say and the way they say them are products of who they are, so knowing as much about them as possible will dictate their speech. This covers the usual gamut of physical, social, and psychological aspects that make people who they are.
Are they educated, or school drop-outs? Is this language they're speaking their first language? What age group? Who are their friends? What is/was their family setting like? Any physical defects that could affect their speech? How do they behave in different social settings? When around strangers, they may guard their speech, but when around friends, they're free and open. What type of people do they like, or hate? Are they confident around men, and not women? Do they like to show off to be the centre of attention? Do they clam up to avoid attention? Are they thoughtful and slow to anger, choosing words carefully, or are they quick tempered? Rude? Polite? Indifferent? Friendly? Suspicious? Do they have particular phrases that they like?
All of this (and a hell of a lot more) will change how and what is said by each character. Slang and accents are not needed (and can become very annoying) unless the character requires it.
Delve into your characters, ask questions about them, understand them, and see the world through their eyes, not your own.
I believe in creating dialogue touchstones: find each major character a couple of lines that they would say, that no other character would say.
Some of these might be catchphrases, or might sound like catchphrases ("Elementary, my dear Watson," "Le- gen- wait for it!", "Everybody lies,"). That's fine, because catchphrases are often attempts to represent the character and his voice. But it can also be something more specific, or less bombastic - simply an example of the way this person talks. The trick is to find distinguishing examples - there are lots of things two characters could say precisely the same way; those won't be as helpful here.
A lot of the examples in Christopher Mahan's answer would serve admirably. And a lot of the points in Craig Sefton's answer will help you find situations where two characters will speak differently. A succinct rule of thumb might be this: a person's personality is revealed by his speech. If you write a line that tells you nothing about a character, consider how that character's personality might make him phrase it differently. An obnoxious character will say it obnoxiously; a worried character will be tense and nervous; somebody confident will speak with certainty and authority. So: find a few lines that you're able to shift around and polish until you're able to say, "Yes, yes, that's exactly how this character would say this; that's him speaking."
Once you've got those lines as touchstones, they're helpful in finding the voice. They jump-start you into that character's way of expressing himself. You can imagine the character speaking the touchstone line to somebody else, and then turning back to the scene at hand for his next line; for me, once I've spoken one line that gets me into the character, I find that the next lines flow much more easily.
(This is actually an insight I picked up from amateur acting. I'd find my character's voice by warming up with some of his loudest, most melodramatic, most distinctive lines - the ones I found easiest to act "well," the ones most obviously "in character." From there, continuing into less-distinctive lines while retaining the character's distinctive voice was a lot easier than starting cold.)
I personally use tricks like making one character speak in riddles, or in short cryptic answers, or even starting with a tick.
Something that works sometimes is to make someone very dull, or too intellectual. Or immature, or overtly sexual. This has to fit in the character.
It is possible to also purposedly mingle the two. An old couple:
Or twin boys playing.
In this case, it actually doesn't matter which one is speaking...
The old man and his old wife:
The gentlemanly teen with an older girl:
A lot is revealed of each character by what they will say and won't say. A seasoned sailor, a gent and a port girl.
The characters are never speaking to the reader, but to each other. It's up to the reader to follow along. Sometimes the mystery is more interesting than the content.
The reader wants to be able to associate mentally with the characters. Those that open themselves up more, that make themselves more vulnerable, are more likely to feel real to the audience.
You'll notice Ben did not speak, and yet much was said. Ben, the silent one, speaks with gestures and emotion. That's his voice, and his spoken words would only support his overall demeanor.
Each character must find his own voice.
I think Craig's answer is solid, but in terms of getting the balance right, one trick I use is to read the dialogue out loud. It works even better if you can rope someone else into reading one of the characters, and treat your MS like a script.
I don't usually do it for the entire book, just for a few key scenes until I have the character's voice in my head. After that, I still make sure that I 'play' the dialogue in my head, like watching a movie, but I don't generally have to read out the entire book. If I get stuck, then I jump back to reading out loud.